1, Get by code SHA1:
public static String getSHA1(Context context) { try { PackageManager pm =
context.getPackageManager();// Get package manager String packageName =
context.getPackageName(); // Get package name PackageInfo info =
pm.getPackageInfo(packageName, 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 (Exception e) { e.printStackTrace(); } return
null; }
 

2, Get by code MD5:
public static String getMD5(Context context) { try { PackageManager pm =
context.getPackageManager();// Get package manager String packageName =
context.getPackageName(); // Get package name PackageInfo packageInfo =
pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES); Signature[]
signatures = packageInfo.signatures;// Signature information byte[] signatureByte =
signatures[0].toByteArray(); ByteArrayInputStream inputStream = new
ByteArrayInputStream(signatureByte);// Convert signature to byte array stream CertificateFactory
certFactory = CertificateFactory.getInstance("X.509");// Certificate factory , This class implements the function of factory certificate algorithm
X509Certificate cert = (X509Certificate)
certFactory.generateCertificate(inputStream);// X509 certificate ,X.509 Is a very common certificate format
MessageDigest md = MessageDigest.getInstance("MD5");// MD5 encryption algorithm byte[] publicKey
= md.digest(cert.getEncoded());// Get public key StringBuilder str = new
StringBuilder(publicKey.length * 2); for (int i = 0; i < publicKey.length; i++)
{ String h = Integer.toHexString(publicKey[i]); int l = h.length(); if (l == 1)
h = "0" + h; if (l > 2) h = h.substring(l - 2, l); str.append(h.toUpperCase());
if (i < (publicKey.length - 1)) str.append(':'); } return str.toString(); }
catch (Exception e) { e.printStackTrace(); } return null; }

 

 

 

Technology
©2019-2020 Toolsou All rights reserved,
It's unexpected Python Cherry tree (turtle The gorgeous style of Library )Unity3D of UGUI Basics -- Three modes of canvas os Simple use of module computer network --- Basic concepts of computer network ( agreement , system )html Writing about cherry trees , Writing about cherry trees Some East 14 Pay change 16 salary , Sincerity or routine ?Unity-Demo Examples ✨ realization UI- Backpack equipment drag function 06【 Interpretation according to the frame 】 Data range filtering -- awesome java Four functional interfaces ( a key , simple )