Package org.apache.cassandra.security
Class PEMReader
java.lang.Object
org.apache.cassandra.security.PEMReader
This is a helper class to read private keys and X509 certifificates encoded based on PEM (RFC 1421)
format. It can read Password Based Encrypted (PBE henceforth) private keys as well as non-encrypted private keys
along with the X509 certificates/cert-chain based on the textual encoding defined in the RFC 7468
The input private key must be in PKCS#8 format.
It returns PKCS#8 formatted private key and X509 certificates.
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe private key can be with any of these algorithms in order for this read to successfully parse it. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Certificate[]extractCertificates(String pemCerts) Extracts the certificates/cert-chain from the PEM content.static PrivateKeyextractPrivateKey(String unencryptedPEMKey) Extracts private key from the PEM content for the private key, assuming its not PBE.static PrivateKeyextractPrivateKey(String pemKey, String keyPassword) Extracts private key from the Password Based Encrypted PEM content for the private key.
-
Field Details
-
SUPPORTED_PRIVATE_KEY_ALGORITHMS
The private key can be with any of these algorithms in order for this read to successfully parse it. Currently, supported algorithms are,RSA, DSA or ECThe first one to be evaluated is RSA, being the most common for private keys.
-
-
Constructor Details
-
PEMReader
public PEMReader()
-
-
Method Details
-
extractPrivateKey
public static PrivateKey extractPrivateKey(String unencryptedPEMKey) throws IOException, GeneralSecurityException Extracts private key from the PEM content for the private key, assuming its not PBE.- Parameters:
unencryptedPEMKey- private key stored as PEM content- Returns:
PrivateKeyupon successful reading of the private key- Throws:
IOException- in case PEM reading failsGeneralSecurityException- in case any issue encountered while reading the private key
-
extractPrivateKey
public static PrivateKey extractPrivateKey(String pemKey, String keyPassword) throws IOException, GeneralSecurityException Extracts private key from the Password Based Encrypted PEM content for the private key.- Parameters:
pemKey- PBE private key stored as PEM contentkeyPassword- password to be used for the private key decryption- Returns:
PrivateKeyupon successful reading of the private key- Throws:
IOException- in case PEM reading failsGeneralSecurityException- in case any issue encountered while reading the private key
-
extractCertificates
Extracts the certificates/cert-chain from the PEM content.- Parameters:
pemCerts- certificates/cert-chain stored as PEM content- Returns:
- X509 certiificate list
- Throws:
GeneralSecurityException- in case any issue encountered while reading the certificates
-