Package org.wildfly.security.pem
Class Pem
- java.lang.Object
-
- org.wildfly.security.pem.Pem
-
public final class Pem extends Object
A class containing utilities which can handle the PEM format. See RFC 7468 for more information.- Author:
- David M. Lloyd
-
-
Constructor Summary
Constructors Constructor Description Pem()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]extractDerContent(org.wildfly.common.iteration.CodePointIterator pemContent)Extracts the DER content from the givenpemContent.static voidgeneratePemContent(org.wildfly.common.bytes.ByteStringBuilder target, String type, org.wildfly.common.iteration.ByteIterator content)Generate PEM content to the given byte string builder.static voidgeneratePemPKCS10CertificateSigningRequest(org.wildfly.common.bytes.ByteStringBuilder target, PKCS10CertificateSigningRequest certificateSigningRequest)Generate PEM content containing a PKCS #10 certificate signing request.static voidgeneratePemPublicKey(org.wildfly.common.bytes.ByteStringBuilder target, PublicKey publicKey)Generate PEM content containing aPublicKey.static voidgeneratePemX509Certificate(org.wildfly.common.bytes.ByteStringBuilder target, X509Certificate certificate)Generate PEM content containing an X.509 certificate.static Iterator<PemEntry<?>>parsePemContent(org.wildfly.common.iteration.CodePointIterator pemContent)Iterate over the contents of a PEM file, returning each entry in sequence.static <R> RparsePemContent(org.wildfly.common.iteration.CodePointIterator pemContent, BiFunction<String,org.wildfly.common.iteration.ByteIterator,R> contentFunction)Parse arbitrary PEM content.static PublicKeyparsePemPublicKey(org.wildfly.common.iteration.CodePointIterator pemContent)Parse aPublicKeyin PEM format.static X509CertificateparsePemX509Certificate(org.wildfly.common.iteration.CodePointIterator pemContent)Parse an X.509 certificate in PEM format.
-
-
-
Method Detail
-
parsePemContent
public static <R> R parsePemContent(org.wildfly.common.iteration.CodePointIterator pemContent, BiFunction<String,org.wildfly.common.iteration.ByteIterator,R> contentFunction) throws IllegalArgumentExceptionParse arbitrary PEM content. The given function is used to parse the content of the PEM representation and produce some result. The PEM type string is passed to the function. If the function throws an exception, that exception is propagated to the caller of this method. If the PEM content is malformed, an exception is thrown. If the trailing PEM content is found to be invalid after the function returns, the function result is discarded and an exception is thrown.- Type Parameters:
R- the value return type- Parameters:
pemContent- the content to parse (must not benull)contentFunction- a function to consume the PEM content and produce a result (must not benull)- Returns:
- the return value of the function or
nullif there is no PEM content to parse - Throws:
IllegalArgumentException- if there is a problem with processing the content of the PEM data
-
parsePemContent
public static Iterator<PemEntry<?>> parsePemContent(org.wildfly.common.iteration.CodePointIterator pemContent)
Iterate over the contents of a PEM file, returning each entry in sequence.- Parameters:
pemContent- the code point iterator over the content (must not benull)- Returns:
- the iterator (not
null)
-
generatePemContent
public static void generatePemContent(org.wildfly.common.bytes.ByteStringBuilder target, String type, org.wildfly.common.iteration.ByteIterator content) throws IllegalArgumentExceptionGenerate PEM content to the given byte string builder. The appropriate header and footer surrounds the base-64 encoded value.- Parameters:
target- the target byte string builder (must not benull)type- the content type (must not benull)content- the content iterator (must not benull)- Throws:
IllegalArgumentException- if there is a problem with the data or the type
-
extractDerContent
public static byte[] extractDerContent(org.wildfly.common.iteration.CodePointIterator pemContent)
Extracts the DER content from the givenpemContent.- Parameters:
pemContent- aCodePointIteratorwith the PEM content- Returns:
- a byte array with the DER content
-
parsePemX509Certificate
public static X509Certificate parsePemX509Certificate(org.wildfly.common.iteration.CodePointIterator pemContent) throws IllegalArgumentException
Parse an X.509 certificate in PEM format.- Parameters:
pemContent- the PEM content (must not benull)- Returns:
- the certificate (not
null) - Throws:
IllegalArgumentException- if the certificate could not be parsed for some reason
-
parsePemPublicKey
public static PublicKey parsePemPublicKey(org.wildfly.common.iteration.CodePointIterator pemContent) throws IllegalArgumentException
Parse aPublicKeyin PEM format.- Parameters:
pemContent- the PEM content (must not benull)- Returns:
- the public key (not
null) - Throws:
IllegalArgumentException- if the public key could not be parsed for some reason
-
generatePemX509Certificate
public static void generatePemX509Certificate(org.wildfly.common.bytes.ByteStringBuilder target, X509Certificate certificate)Generate PEM content containing an X.509 certificate.- Parameters:
target- the target byte string builder (must not benull)certificate- the X.509 certificate (must not benull)
-
generatePemPublicKey
public static void generatePemPublicKey(org.wildfly.common.bytes.ByteStringBuilder target, PublicKey publicKey)Generate PEM content containing aPublicKey.- Parameters:
target- the target byte string builder (must not benull)publicKey- thePublicKey(must not benull)
-
generatePemPKCS10CertificateSigningRequest
public static void generatePemPKCS10CertificateSigningRequest(org.wildfly.common.bytes.ByteStringBuilder target, PKCS10CertificateSigningRequest certificateSigningRequest)Generate PEM content containing a PKCS #10 certificate signing request.- Parameters:
target- the target byte string builder (must not benull)certificateSigningRequest- the PKCS #10 certificate signing request (must not benull)- Since:
- 1.2.0
-
-