public static String getSHA1(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[] signatures = md.digest(cert);
StringBuffer sha1 = new StringBuffer();
int i = 0;
for (byte key : signatures) {
String appendString = Integer.toHexString(0xFF & key).toUpperCase(Locale.US);
if (appendString.length() == 1)
sha1.append("0");
sha1.append(appendString);
if (signatures.length - 1 == i)
break;
sha1.append(":");
i++;
}
return sha1.toString();
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
Android代码获取sha1
最新推荐文章于 2020-09-29 15:25:54 发布