Skip to content

Commit

Permalink
Add javadoc to the EncryptedPKCS8Parser class
Browse files Browse the repository at this point in the history
  • Loading branch information
cescoffier committed Nov 15, 2024
1 parent 09e0a1d commit 729d82d
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Parser for PKCS#8 format encrypted private keys.
*/
public class EncryptedPKCS8Parser implements PKPemParser {

private static final String PKCS8_ENCRYPTED_START = "-+BEGIN\\s+ENCRYPTED\\s+PRIVATE\\s+KEY[^-]*-+(?:\\s|\\r|\\n)+";
Expand All @@ -34,6 +37,12 @@ public class EncryptedPKCS8Parser implements PKPemParser {
public EncryptedPKCS8Parser() {
}

/**
* Extracts the private key from the encrypted PKCS#8 format.
* @param content the encrypted PKCS#8 content
* @param password the password to decrypt the key
* @return the private key or {@code null} if the content is not a PKCS#8 encrypted key
*/
@Override
public PrivateKey getKey(String content, String password) {
try {
Expand Down Expand Up @@ -87,6 +96,12 @@ private static String getEncryptionAlgorithm(AlgorithmParameters algParameters,
return algName;
}

/**
* Retrieves the private key as plain PKCS#8 from the encrypted PKCS#8 content.
* @param content the encrypted PKCS#8 content
* @param secret the password to decrypt the key
* @return the decrypted PKCS#8 key or {@code null} if the content is not a PKCS#8 encrypted key
*/
public Buffer decryptKey(String content, String secret) {
var pk = getKey(content, secret);
if (pk == null) {
Expand Down

0 comments on commit 729d82d

Please sign in to comment.