org.jclouds.crypto
Class Pems

java.lang.Object
  extended by org.jclouds.crypto.Pems

@Beta
public class Pems
extends Object

Reads and writes PEM encoded Strings and Streams

Author:
Adrian Cole

Nested Class Summary
static class Pems.PemProcessor<T>
           
 
Field Summary
static String CERTIFICATE_X509_MARKER
           
static String PRIVATE_PKCS1_MARKER
           
static String PRIVATE_PKCS8_MARKER
           
static String PUBLIC_PKCS1_MARKER
           
static String PUBLIC_X509_MARKER
           
 
Constructor Summary
Pems()
           
 
Method Summary
static
<T> T
fromPem(com.google.common.io.InputSupplier<? extends InputStream> supplier, Pems.PemProcessor<T> processor)
          Returns the object of generic type T that is pem encoded in the supplier.
static byte[] getEncoded(RSAPrivateCrtKey key)
           
static String pem(PrivateKey key)
          encodes the PrivateKey to PEM format.
static String pem(PublicKey key)
          encodes the PublicKey to PEM format.
static String pem(X509Certificate cert)
          encodes the X509Certificate to PEM format.
static KeySpec privateKeySpec(com.google.common.io.InputSupplier<? extends InputStream> supplier)
          Returns the RSAPrivateKeySpec that is pem encoded in the supplier.
static KeySpec privateKeySpec(String pem)
          Executes privateKeySpec(InputSupplier) on the string which contains an encoded private key in PEM format.
static KeySpec publicKeySpec(com.google.common.io.InputSupplier<? extends InputStream> supplier)
          Returns the KeySpec that is pem encoded in the supplier.
static KeySpec publicKeySpec(String pem)
          Executes publicKeySpec(InputSupplier) on the string which contains an encoded public key in PEM format.
static X509Certificate x509Certificate(com.google.common.io.InputSupplier<? extends InputStream> supplier, CertificateFactory certFactory)
          Returns the X509EncodedKeySpec that is pem encoded in the supplier.
static X509Certificate x509Certificate(String pem)
          Executes x509Certificate(InputSupplier, CertificateFactory) on the string which contains an X.509 certificate in PEM format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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
Constructor Detail

Pems

public Pems()
Method Detail

fromPem

public static <T> T fromPem(com.google.common.io.InputSupplier<? extends InputStream> supplier,
                            Pems.PemProcessor<T> processor)
                 throws IOException
Returns the object of generic type T that is pem encoded in the supplier.

Parameters:
supplier - the input stream factory
marker - header that begins the PEM block
processor - how to parser the object from a byte array
Returns:
the object of generic type T which was PEM encoded in the stream
Throws:
IOException - if an I/O error occurs

privateKeySpec

public static KeySpec privateKeySpec(com.google.common.io.InputSupplier<? extends InputStream> supplier)
                              throws IOException
Returns the RSAPrivateKeySpec that is pem encoded in the supplier.

Parameters:
supplier - the input stream factory
Returns:
the RSAPrivateKeySpec which was PEM encoded in the stream
Throws:
IOException - if an I/O error occurs

privateKeySpec

public static KeySpec privateKeySpec(String pem)
Executes privateKeySpec(InputSupplier) on the string which contains an encoded private key in PEM format.

Parameters:
pem - private key in pem encoded format.
See Also:
privateKeySpec(InputSupplier)

publicKeySpec

public static KeySpec publicKeySpec(com.google.common.io.InputSupplier<? extends InputStream> supplier)
                             throws IOException
Returns the KeySpec that is pem encoded in the supplier.

Parameters:
supplier - the input stream factory
Returns:
the KeySpec which was PEM encoded in the stream
Throws:
IOException - if an I/O error occurs

publicKeySpec

public static KeySpec publicKeySpec(String pem)
                             throws IOException
Executes publicKeySpec(InputSupplier) 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(InputSupplier)

x509Certificate

public static X509Certificate x509Certificate(com.google.common.io.InputSupplier<? extends InputStream> supplier,
                                              @Nullable
                                              CertificateFactory certFactory)
                                       throws IOException,
                                              CertificateException
Returns the X509EncodedKeySpec that is pem encoded in the supplier.

Parameters:
supplier - the input stream factory
certFactory - or null to use default
Returns:
the X509EncodedKeySpec which was PEM encoded in the stream
Throws:
IOException - if an I/O error occurs
CertificateException

x509Certificate

public static X509Certificate x509Certificate(String pem)
                                       throws IOException,
                                              CertificateException
Executes x509Certificate(InputSupplier, CertificateFactory) on the string which contains an X.509 certificate in PEM format.

Parameters:
pem - certificate in pem encoded format.
Throws:
IOException
CertificateException
See Also:
x509Certificate(InputSupplier, CertificateFactory)

pem

public static String pem(X509Certificate cert)
                  throws CertificateEncodingException
encodes the X509Certificate to PEM format.

Parameters:
cert - what to encode
Returns:
the PEM encoded certificate
Throws:
IOException
CertificateEncodingException

pem

public static String pem(PublicKey key)
encodes the PublicKey to PEM format.

Parameters:
cert - what to encode
Returns:
the PEM encoded public key
Throws:
IOException
CertificateEncodingException

pem

public static String pem(PrivateKey key)
encodes the PrivateKey to PEM format. Note

Parameters:
cert - what to encode
Returns:
the PEM encoded private key
Throws:
IOException
CertificateEncodingException

getEncoded

public static byte[] getEncoded(RSAPrivateCrtKey key)


Copyright © 2009-2012 jclouds. All Rights Reserved.