美文网首页
Android获取签名MD5

Android获取签名MD5

作者: 2b75747cf703 | 来源:发表于2017-03-16 10:59 被阅读414次
        public void printSignatureMD5() {
            try {
                PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
    
                Log.e("getMD5MessageDigest", getMD5MessageDigest(packageInfo.signatures[0].toByteArray()));
    
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public static String getMD5MessageDigest(byte[] bytes) {
            StringBuffer md5StringBuffer = new StringBuffer();
            try {
                MessageDigest messageDigest = MessageDigest.getInstance("MD5");
                messageDigest.reset();
                messageDigest.update(bytes);
                byte[] digest = messageDigest.digest();
                for (int i = 0; i < digest.length; i++) {
                    String hexString = Integer.toHexString(digest[i] & 0xff);
    
                    if (hexString.length() == 1)
                        md5StringBuffer.append("0");
    
                    md5StringBuffer.append(hexString);
                }
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            }
            return md5StringBuffer.toString();
        }
    

    相关文章

      网友评论

          本文标题:Android获取签名MD5

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