Last active
August 29, 2015 14:10
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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