Created
November 18, 2016 22:57
-
-
Save ashee/ae3f14e7f2722571b3b366f5cf9d1abb to your computer and use it in GitHub Desktop.
Read private key from jks keystore
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
import java.security.Key | |
import java.security.KeyStore | |
def console = System.console() | |
def keystoreName = "amitava.jks" | |
def keystoreFormat = "JKS" | |
def keystorePassword = console.readPassword("%s ", "Keystore Password:").toString() | |
def alias = "amitava" | |
def keyPassword = console.readPassword("%s ", "Alias Password:").toString() | |
def keystore = KeyStore.getInstance(keystoreFormat) | |
keystore.load(new FileInputStream(keystoreName), keystorePassword.toCharArray()) | |
def key = keystore.getKey(alias, keyPassword.toCharArray()) | |
println(key) | |
println "-----BEGIN PRIVATE KEY-----" | |
println key.getEncoded().encodeBase64() | |
println "-----END PRIVATE KEY-----" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment