Generate Hash Key required for Facebook login
fun printHashKey(pContext: Context) {
try {
val info: PackageInfo = pContext.getPackageManager().getPackageInfo(pContext.getPackageName(), PackageManager.GET_SIGNATURES)
for (signature in info.signatures) {
val md = MessageDigest.getInstance("SHA")
md.update(signature.toByteArray())
val hashKey = String(Base64.encode(md.digest(), 0))
Log.i("TAG", "printHashKey() Hash Key: $hashKey")
}
} catch (e: NoSuchAlgorithmException) {
Log.e("TAG", "printHashKey()", e)
} catch (e: Exception) {
Log.e("TAG", "printHashKey()", e)
}
}
// Java
private void printHashKey(Context pContext) {
try {
PackageInfo info = pContext.getPackageManager().getPackageInfo(pContext.getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String hashKey = new String(Base64.encode(md.digest(), 0));
Log.i("TAG", "printHashKey() Hash Key: "+hashKey);
}
} catch (NoSuchAlgorithmException e) {
Log.e("TAG", "printHashKey()", e);
} catch (Exception e) {
Log.e("TAG", "printHashKey()", e);
}
}