diff --git a/private-key-pem-parser/src/main/java/io/smallrye/certs/pem/parsers/EncryptedPKCS8Parser.java b/private-key-pem-parser/src/main/java/io/smallrye/certs/pem/parsers/EncryptedPKCS8Parser.java index dc6d7fd..b4f6795 100644 --- a/private-key-pem-parser/src/main/java/io/smallrye/certs/pem/parsers/EncryptedPKCS8Parser.java +++ b/private-key-pem-parser/src/main/java/io/smallrye/certs/pem/parsers/EncryptedPKCS8Parser.java @@ -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)+"; @@ -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 { @@ -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) {