Skip to content

Instantly share code, notes, and snippets.

@nsainaney
Last active August 29, 2015 14:10
Show Gist options
  • Save nsainaney/67195bdf6e0ee7c6d5db to your computer and use it in GitHub Desktop.
Save nsainaney/67195bdf6e0ee7c6d5db to your computer and use it in GitHub Desktop.
Xamarin Dump HASH for use in Facebook Android SDK (instead of using keytool)
void DumpKeyHashes()
{
try
{
using (var sha = new System.Security.Cryptography.SHA1CryptoServiceProvider())
{
//Retriving package info
var packageName = ApplicationContext.PackageName;
System.Diagnostics.Debug.WriteLine("#### PACKAGE NAME: " + packageName);
var packageInfo = this.PackageManager.GetPackageInfo(packageName, PackageInfoFlags.Signatures);
foreach (var signature in packageInfo.Signatures)
{
var sigBytes = signature.ToByteArray();
// This is one implementation of the abstract class SHA1.
var result = sha.ComputeHash(sigBytes);
System.Diagnostics.Debug.WriteLine("#### SHA1 KEY: " + BitConverter.ToString(result).Replace('-', ':'));
var key = System.Convert.ToBase64String(result);
System.Diagnostics.Debug.WriteLine("#### HASH KEY: " + key);
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("#### HASH KEY EXCEPTION:" + ex.Message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment