-
-
Save ryctabo/c8553f9da607c67a8c159e1da0509cdc to your computer and use it in GitHub Desktop.
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
KeyFactory keyFactory = KeyFactory.getInstance("RSA"); | |
// Clean public key information | |
String publicKeyContent = new String(getBytesFromUri("id_rsa.pub")); | |
publicKeyContent = publicKeyContent | |
.replace("----BEGIN RSA PUBLIC KEY----", "") | |
.replace("----END RSA PUBLIC KEY----", "") | |
.replace("\n", ""); | |
LOG.info("Public key content: " + publicKeyContent); | |
// Get all bytes decoded from the public key content | |
byte[] publicKeyDecoded = Base64.getDecoder() | |
.decode(publicKeyContent); | |
// Generate the public key object from bytes | |
X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(publicKeyDecoded); | |
PublicKey publicKey = keyFactory.generatePublic(publicKeySpec); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment