Skip to content

Having trouble formatting private key for RSA signature #952

Discussion options

You must be logged in to vote

Was able to figure this out with help from: Stack overflow, and switching to import org.apache.commons.codec.binary.Base64 for the decoder.

// Formatting key
StringBuilder pkcs8Lines = new StringBuilder();
BufferedReader rdr = new BufferedReader(new StringReader(BASEKEY));
String line;
while ((line = rdr.readLine()) != null) {
    pkcs8Lines.append(line);
}
// Cleaning key 
String pkcs8Pem = pkcs8Lines.toString();
pkcs8Pem = pkcs8Pem.replace("-----BEGIN PRIVATE KEY-----", "");
pkcs8Pem = pkcs8Pem.replace("-----END PRIVATE KEY-----", "");
pkcs8Pem = pkcs8Pem.replaceAll("\\s+","");
// Decoding key
byte[] valueDecoded = Base64.decodeBase64(pkcs8Pem);
PKCS8EncodedKeySpec keySpec = new PKCS8En…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@lhazlewood
Comment options

@lhazlewood
Comment options

@lhazlewood
Comment options

@scottmacdonaldclearobject
Comment options

@lhazlewood
Comment options

Answer selected by lhazlewood
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants