美文网首页
获取应用的sha1值

获取应用的sha1值

作者: 会Android的摄影爱好者 | 来源:发表于2017-05-17 15:45 被阅读68次

public staticString 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 =newStringBuffer();

for(inti =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();

returnresult.substring(0, result.length() -1);

}catch(PackageManager.NameNotFoundException e) {

e.printStackTrace();

}catch(NoSuchAlgorithmException e) {

e.printStackTrace();

}

return null;

}

相关文章

网友评论

      本文标题:获取应用的sha1值

      本文链接:https://www.haomeiwen.com/subject/yfvdxxtx.html