Package org.jclouds.crypto
Class Pems
- java.lang.Object
-
- org.jclouds.crypto.Pems
-
@Beta public class Pems extends Object
Reads and writes PEM encoded Strings and Streams
-
-
Field Summary
Fields Modifier and Type Field Description static StringCERTIFICATE_X509_MARKERstatic StringPRIVATE_PKCS1_MARKERstatic StringPRIVATE_PKCS8_MARKERstatic StringPROC_TYPE_ENCRYPTEDstatic StringPUBLIC_PKCS1_MARKERstatic StringPUBLIC_X509_MARKER
-
Constructor Summary
Constructors Constructor Description Pems()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TfromPem(com.google.common.io.ByteSource supplier, org.jclouds.crypto.Pems.PemProcessor<T> processor)Returns the object of generic typeTthat is pem encoded in the supplier.static Stringpem(X509Certificate cert)encodes theX509Certificateto PEM format.static Stringpem(PrivateKey key)encodes thePrivateKeyto PEM format.static Stringpem(PublicKey key)encodes thePublicKeyto PEM format.static KeySpecprivateKeySpec(com.google.common.io.ByteSource supplier)Returns theRSAPrivateKeySpecthat is pem encoded in the supplier.static KeySpecprivateKeySpec(String pem)ExecutesprivateKeySpec(ByteSource)on the string which contains an encoded private key in PEM format.static KeySpecpublicKeySpec(com.google.common.io.ByteSource supplier)Returns theKeySpecthat is pem encoded in the supplier.static KeySpecpublicKeySpec(String pem)ExecutespublicKeySpec(ByteSource)on the string which contains an encoded public key in PEM format.static X509Certificatex509Certificate(com.google.common.io.ByteSource supplier, CertificateFactory certFactory)Returns theX509EncodedKeySpecthat is pem encoded in the supplier.static X509Certificatex509Certificate(String pem)Executesx509Certificate(ByteSource, CertificateFactory)on the string which contains an X.509 certificate in PEM format.
-
-
-
Field Detail
-
PRIVATE_PKCS1_MARKER
public static final String PRIVATE_PKCS1_MARKER
- See Also:
- Constant Field Values
-
PRIVATE_PKCS8_MARKER
public static final String PRIVATE_PKCS8_MARKER
- See Also:
- Constant Field Values
-
CERTIFICATE_X509_MARKER
public static final String CERTIFICATE_X509_MARKER
- See Also:
- Constant Field Values
-
PUBLIC_X509_MARKER
public static final String PUBLIC_X509_MARKER
- See Also:
- Constant Field Values
-
PUBLIC_PKCS1_MARKER
public static final String PUBLIC_PKCS1_MARKER
- See Also:
- Constant Field Values
-
PROC_TYPE_ENCRYPTED
public static final String PROC_TYPE_ENCRYPTED
- See Also:
- Constant Field Values
-
-
Method Detail
-
fromPem
public static <T> T fromPem(com.google.common.io.ByteSource supplier, org.jclouds.crypto.Pems.PemProcessor<T> processor) throws IOExceptionReturns the object of generic typeTthat is pem encoded in the supplier.- Parameters:
supplier- the input stream factorymarker- header that begins the PEM blockprocessor- how to parser the object from a byte array- Returns:
- the object of generic type
Twhich was PEM encoded in the stream - Throws:
IOException- if an I/O error occurs
-
privateKeySpec
public static KeySpec privateKeySpec(com.google.common.io.ByteSource supplier) throws IOException
Returns theRSAPrivateKeySpecthat is pem encoded in the supplier.- Parameters:
supplier- the input stream factory- Returns:
- the
RSAPrivateKeySpecwhich was PEM encoded in the stream - Throws:
IOException- if an I/O error occurs
-
privateKeySpec
public static KeySpec privateKeySpec(String pem)
ExecutesprivateKeySpec(ByteSource)on the string which contains an encoded private key in PEM format.- Parameters:
pem- private key in pem encoded format.- See Also:
privateKeySpec(ByteSource)
-
publicKeySpec
public static KeySpec publicKeySpec(com.google.common.io.ByteSource supplier) throws IOException
Returns theKeySpecthat is pem encoded in the supplier.- Parameters:
supplier- the input stream factory- Returns:
- the
KeySpecwhich was PEM encoded in the stream - Throws:
IOException- if an I/O error occurs
-
publicKeySpec
public static KeySpec publicKeySpec(String pem) throws IOException
ExecutespublicKeySpec(ByteSource)on the string which contains an encoded public key in PEM format.- Parameters:
pem- public key in pem encoded format.- Throws:
IOException- See Also:
publicKeySpec(ByteSource)
-
x509Certificate
public static X509Certificate x509Certificate(com.google.common.io.ByteSource supplier, @Nullable CertificateFactory certFactory) throws IOException, CertificateException
Returns theX509EncodedKeySpecthat is pem encoded in the supplier.- Parameters:
supplier- the input stream factorycertFactory- or null to use default- Returns:
- the
X509EncodedKeySpecwhich was PEM encoded in the stream - Throws:
IOException- if an I/O error occursCertificateException
-
x509Certificate
public static X509Certificate x509Certificate(String pem) throws IOException, CertificateException
Executesx509Certificate(ByteSource, CertificateFactory)on the string which contains an X.509 certificate in PEM format.- Parameters:
pem- certificate in pem encoded format.- Throws:
IOExceptionCertificateException- See Also:
x509Certificate(ByteSource, CertificateFactory)
-
pem
public static String pem(X509Certificate cert) throws CertificateEncodingException
encodes theX509Certificateto PEM format.- Parameters:
cert- what to encode- Returns:
- the PEM encoded certificate
- Throws:
IOExceptionCertificateEncodingException
-
pem
public static String pem(PrivateKey key)
encodes thePrivateKeyto PEM format.
-
-