Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read SHA and MD5 fingerprint programmatically in Android

Hello I want to read SHA and MD5 fingerprint value of keystore programmatically of my app from which it was signed.

I'll take either SHA or MD5 value as key for security. This key I will use in the code to encrypt something and decrypt same at server end.

Is there any way to find this or is there any way to do same using different good approach. This should be in such a way nobody other can find this key.

Thanks in advance.

like image 330
N Sharma Avatar asked Jan 31 '15 11:01

N Sharma


1 Answers

PackageInfo info;
try {

    info = getPackageManager().getPackageInfo(
        "com.your.package.name", PackageManager.GET_SIGNATURES);

    for (Signature signature : info.signatures) {
        MessageDigest md;
        md = MessageDigest.getInstance("SHA");
        md.update(signature.toByteArray());
        String hash_key = new String(Base64.encode(md.digest(), 0));
    }

} catch (NameNotFoundException e1) {
} catch (NoSuchAlgorithmException e) {
} catch (Exception e) {
}
like image 103
nbaroz Avatar answered Oct 20 '22 23:10

nbaroz