Package org.keycloak.common.util
Class PemUtils
- java.lang.Object
-
- org.keycloak.common.util.PemUtils
-
public class PemUtils extends Object
Utility classes to extract PublicKey, PrivateKey, and X509Certificate from openssl generated PEM files- Version:
- $Revision: 1 $
- Author:
- Bill Burke
-
-
Field Summary
Fields Modifier and Type Field Description static String
BEGIN_CERT
static String
BEGIN_PRIVATE_KEY
static String
BEGIN_RSA_PRIVATE_KEY
static String
END_CERT
static String
END_PRIVATE_KEY
static String
END_RSA_PRIVATE_KEY
-
Constructor Summary
Constructors Constructor Description PemUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
addPrivateKeyBeginEnd(String privateKeyPem)
static String
addRsaPrivateKeyBeginEnd(String privateKeyPem)
static X509Certificate
decodeCertificate(String cert)
Decode a X509 Certificate from a PEM stringstatic PrivateKey
decodePrivateKey(String pem)
Decode a Private Key from a PEM stringstatic PublicKey
decodePublicKey(String pem)
Decode a Public Key from a PEM stringstatic PublicKey
decodePublicKey(String pem, String type)
Decode a Public Key from a PEM stringstatic String
encodeCertificate(Certificate certificate)
Encode a X509 Certificate to a PEM stringstatic String
encodeKey(Key key)
Encode a Key to a PEM stringstatic String
generateThumbprint(String[] certChain, String encoding)
static byte[]
pemToDer(String pem)
static String
removeBeginEnd(String pem)
-
-
-
Field Detail
-
BEGIN_CERT
public static final String BEGIN_CERT
- See Also:
- Constant Field Values
-
END_CERT
public static final String END_CERT
- See Also:
- Constant Field Values
-
BEGIN_PRIVATE_KEY
public static final String BEGIN_PRIVATE_KEY
- See Also:
- Constant Field Values
-
END_PRIVATE_KEY
public static final String END_PRIVATE_KEY
- See Also:
- Constant Field Values
-
BEGIN_RSA_PRIVATE_KEY
public static final String BEGIN_RSA_PRIVATE_KEY
- See Also:
- Constant Field Values
-
END_RSA_PRIVATE_KEY
public static final String END_RSA_PRIVATE_KEY
- See Also:
- Constant Field Values
-
-
Method Detail
-
decodeCertificate
public static X509Certificate decodeCertificate(String cert)
Decode a X509 Certificate from a PEM string- Parameters:
cert
-- Returns:
- Throws:
Exception
-
decodePublicKey
public static PublicKey decodePublicKey(String pem)
Decode a Public Key from a PEM string- Parameters:
pem
-- Returns:
- Throws:
Exception
-
decodePublicKey
public static PublicKey decodePublicKey(String pem, String type)
Decode a Public Key from a PEM string- Parameters:
pem
- The pem encoded pblic keytype
- The type of the key (RSA, EC,...)- Returns:
- The public key or null
-
decodePrivateKey
public static PrivateKey decodePrivateKey(String pem)
Decode a Private Key from a PEM string- Parameters:
pem
-- Returns:
- Throws:
Exception
-
encodeKey
public static String encodeKey(Key key)
Encode a Key to a PEM string- Parameters:
key
-- Returns:
- Throws:
Exception
-
encodeCertificate
public static String encodeCertificate(Certificate certificate)
Encode a X509 Certificate to a PEM string- Parameters:
certificate
-- Returns:
-
pemToDer
public static byte[] pemToDer(String pem)
-
generateThumbprint
public static String generateThumbprint(String[] certChain, String encoding) throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
-