> For the complete documentation index, see [llms.txt](https://urvish-shiroya-organization.gitbook.io/sha-1-or-sha-256-and-key-hash/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://urvish-shiroya-organization.gitbook.io/sha-1-or-sha-256-and-key-hash/find-hash-key/find-debug-hash-key-using-code.md).

# Find Debug Hash key using Code

If you get a debug hash key from using Code in Android,  you must try this code.

```java
try {
	PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
	for (Signature signature : info.signatures) {
		MessageDigest md = MessageDigest.getInstance("SHA");
		md.update(signature.toByteArray());
		Log.e("MY KEY HASH:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
	}
} catch (NameNotFoundException e) {
	Log.e("KEY HASH ERROR:", "NameNotFoundException: " + e.getMessage());
} catch (NoSuchAlgorithmException e) {
	Log.e("KEY HASH ERROR:", "NoSuchAlgorithmException: " + e.getMessage());
}
```

Put this code into `MainActivity.java` into `onCreate()` function and run the app, you will find key in logcat
