When you publish apk to an application store or to a Third-party SDK, you sometimes need to provide APK signature summary information, a digest algorithm MD5 or SHA-1 to obtain a signature summary, in addition to obtaining your own APK signature, or obtaining other installed apk signatures on your phone, You only need to pass in the other APK package name.
private static final char[] Hex_char = {' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', ' A ', ' B ', ' C ', ' D ', ' E
', ' F '};
/** gets the signature MD5 summary/public string[] Signaturedigest () {pkgInfo = Mcontext.getpackagemanager (). Getpackageinfo (
Mcontext.getpackagename (), packagemanager.get_signatures);
int length = PkgInfo.signatures.length;
String[] digests = new String[length];
for (int i = 0; i < length; ++i) {Signature sign = mpkginfo.signatures[i];
try {messagedigest MD5 = messagedigest.getinstance ("MD5"); Byte[] Digest = Md5.digest (Sign.tobytearray ());
Get digest with MD5 algorithm digests[i] = tohexstring (digest);
catch (NoSuchAlgorithmException e) {e.printstacktrace ();
Digests[i] = null;
} return digests; /** converts a byte array to the corresponding hexadecimal string */private string tohexstring (byte[] rawbytearray) {char[] chars = new Char[rawbytearray
. length * 2]; for (int i = 0; i < Rawbytearray.length;
++i) {byte b = rawbytearray[i];
CHARS[I*2] = hex_char[(b >>> 4 & 0x0f)];
Chars[i*2+1] = hex_char[(b & 0x0f)];
Return to New String (chars); }
The above is the entire content of this article, I hope to help you learn.