private void printHashKey() {
try {
PackageInfo info = getPackageManager().getPackageInfo(
"xxx.xx.xxx.x",
PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String base64Key = Base64.encodeToString(md.digest(), Base64.DEFAULT);
Log.i("hashKey", base64Key);
}
} catch (PackageManager.NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
}
也可以用命令行:
keytool -exportcert -alias <RELEASE_KEY_ALIAS> -keystore <RELEASE_KEY_PATH> | openssl sha1 -binary | openssl base64