获取jks的SHA1值

apk文件需要利用jks进行签名,可以防止应用被恶意篡改替换,标识开发者身份,加强了应用的安全性.(keystore也可以)

第一种利用keytool工具

keytool -list -v -keystore canvaskeystore.jks
获取jks的SHA1值

第二种利用代码获取

从高德获取:

 public static String sHA1(Context context) {
        try {
            PackageInfo info = context.getPackageManager().getPackageInfo(
                    context.getPackageName(), PackageManager.GET_SIGNATURES);
            byte[] cert = info.signatures[0].toByteArray();
            MessageDigest md = MessageDigest.getInstance("SHA1");
            byte[] publicKey = md.digest(cert);
            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < publicKey.length; i++) {
                String appendString = Integer.toHexString(0xFF & publicKey[i])
                        .toUpperCase(Locale.US);
                if (appendString.length() == 1)
                    hexString.append("0");
                hexString.append(appendString);
                hexString.append(":");
            }
            String result = hexString.toString();
            return result.substring(0, result.length()-1);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
上一篇:RK3588超强8K视频输出NRV边缘计算盒 AI人工智能


下一篇:C++中的静态函数static