Skip to content

Instantly share code, notes, and snippets.

@darkstone
Created January 27, 2018 16:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darkstone/5fe9867b7fff499bed37c39467ba8a62 to your computer and use it in GitHub Desktop.
Save darkstone/5fe9867b7fff499bed37c39467ba8a62 to your computer and use it in GitHub Desktop.
How to read RSA private key from SSL command output.
val rivateKey = privateKeyAsText
.replace("-----BEGIN PRIVATE KEY-----\n", "")
.replace("-----END PRIVATE KEY-----", "")
.replace("\n", "")
.let {
val encodedKey = Base64.getDecoder().decode(it)
val kf = KeyFactory.getInstance("RSA")
val keySpec = PKCS8EncodedKeySpec(encodedKey)
kf.generatePrivate(keySpec) as RSAPrivateKey
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment