APP簽名MD5獲取

今天手機集成騰訊視頻又有新需求了,全新的版本,全新的體驗。須要個人MD5簽名,之前還真沒注意過,特此記錄下。app

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();
}
相關文章
相關標籤/搜索