Android-several ways to view SHA1 and MD5

2023-01-30  

Android-several ways to view SHA1 and MD5

1. Get the APK SHA1 and MD5

In order to avoid the wrong signature when registering, it is recommended to directly check the signature with the packed APK. The specifics are as follows:
1) Modify the APK to modify the suffix to the .rar file; decompress;
2) Enter the Meta-INF directory after decompression. In this directory, there will be a file CERT.RSA
3) Open the CMD in this directory and enter the command: KeyTool -printcert -File Cert.rsa

2, obtain in the code

publicstatic 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 (NameNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return null;

3. Use the signature file to get

1) Open the CMD command and enter the keyTool.exe directory. Generally in D: \ Program Files \ Java \ JDK1.8.0_181 \ BIN
2) Enter command: KeyTool -List -KeyStore “(JKS’s directory) App.Keystore (JKS)”
3) Enter the key library password, which refers to the password set when the keystore file is generated before the input. The default is not displayed after the input.

Record

source

Random Posts

HDU 2553 N Queen Question

GOLDENGATE Learning Series 4-LOGDUMP

Codevs 1062 Route Select the shortest road short circuit Dijkstra problem solving report

Two points on the tree recently public ancestor-Tarjanlca offline algorithm

What are the good program design competitions?