Created
February 23, 2020 23:05
-
-
Save naturalett/516def63329f226d4567d1b8d777ec4b to your computer and use it in GitHub Desktop.
getRSAPrivateKey
This file contains 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
def getRSAPrivateKey(privateKey) { | |
try { | |
String privateKeyPEM = readFile privateKey | |
privateKeyPEM = privateKeyPEM.replace("-----BEGIN CERTIFICATE-----\n", ""); | |
privateKeyPEM = privateKeyPEM.replace("-----END CERTIFICATE-----", ""); | |
byte[] encoded = Base64.decodeBase64(privateKeyPEM); | |
KeyFactory kf = KeyFactory.getInstance("RSA"); | |
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encoded); | |
RSAPrivateKey privKey = (RSAPrivateKey) kf.generatePrivate(keySpec); | |
return privKey | |
} catch(Exception e){ | |
echo "Exception: ${e}" | |
error "Failed to create a RSAPrivateKey" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment