Skip to content

Instantly share code, notes, and snippets.

@timkrins
Last active April 26, 2017 15:27
Show Gist options
  • Save timkrins/16e16dec94e23ad2749bcc9ca3c05e70 to your computer and use it in GitHub Desktop.
Save timkrins/16e16dec94e23ad2749bcc9ca3c05e70 to your computer and use it in GitHub Desktop.
Facebook Hash Generator for Android Gradle Console
def getFacebookHash = { ->
try {
def stdOut = new ByteArrayOutputStream()
def stdIn = new ByteArrayInputStream()
exec {
commandLine "keytool", "-exportcert", "-alias", KEY_ALIAS, "-keystore", file(STORE_FILE), "-storepass", STORE_PASSWORD
standardOutput = stdOut
}
stdIn = new ByteArrayInputStream(stdOut.toByteArray())
stdOut = new ByteArrayOutputStream()
exec {
standardInput = stdIn
commandLine file(OPENSSL_BINARY), "sha1", "-binary"
standardOutput = stdOut
}
stdIn = new ByteArrayInputStream(stdOut.toByteArray())
stdOut = new ByteArrayOutputStream()
exec {
standardInput = stdIn
commandLine file(OPENSSL_BINARY), "base64"
standardOutput = stdOut
}
def hashString = stdOut.toString().trim()
return hashString
}
catch (error) {
return error.toString();
}
}
gradle.buildFinished {
println "Facebook Release Key Hash:\n " + getFacebookHash() + "\n"
}
STORE_FILE=C:/Keystore.jks
STORE_PASSWORD=password
KEY_ALIAS=keystoreAlias
KEY_PASSWORD=password
OPENSSL_BINARY=C:/OpenSSL-Win64/bin/openssl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment