com.cedarsoft.crypt
Class X509Support

java.lang.Object
  extended by com.cedarsoft.crypt.X509Support

public class X509Support
extends Object

X509 Support

Author:
Johannes Schneider (js@cedarsoft.com)

Constructor Summary
X509Support(URL certificate)
          Creates a new X509 support without any signing capabilities
X509Support(URL certificate, URL privateKey)
          Creates a new X509 support
X509Support(X509Certificate certificate)
          Creates a new x509 support
X509Support(X509Certificate certificate, RSAPrivateKey privateKey)
          Creates a new x509 support
 
Method Summary
 byte[] cipher(byte[] plainText)
          cipher
 byte[] decipher(byte[] bytes)
          decipher
 X509Certificate getCertificate()
          Returns the certificate
 RSAPrivateKey getPrivateKey()
          Returns the private key (if there is one)
 boolean isPrivateKeyAvailable()
          Returns whether the private key is available
static X509Certificate readCertificate(URL certificateUrl)
          Reads the x509 certificate from the given url
static RSAPrivateKey readPrivateKey(URL privateKeyUrl)
          Reads a private key form a url
 Signature sign(byte[] plainText)
          sign
 boolean verifySignature(byte[] plainText, Signature signature)
          verifySignature
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

X509Support

public X509Support(@Nonnull
                   URL certificate)
            throws IOException,
                   GeneralSecurityException
Creates a new X509 support without any signing capabilities

Parameters:
certificate - the certificate
Throws:
IOException - if any.
GeneralSecurityException - if any.

X509Support

@Inject
public X509Support(@Nonnull
                          URL certificate,
                          @PrivateKeyUrl@Nullable
                          URL privateKey)
            throws IOException,
                   GeneralSecurityException
Creates a new X509 support

Parameters:
certificate - the certificate
privateKey - the private key (if available)
Throws:
IOException - if any.
GeneralSecurityException - if any.

X509Support

public X509Support(@Nonnull
                   X509Certificate certificate)
Creates a new x509 support

Parameters:
certificate - the certificate

X509Support

public X509Support(@Nonnull
                   X509Certificate certificate,
                   @Nullable
                   RSAPrivateKey privateKey)
Creates a new x509 support

Parameters:
certificate - the certificate
privateKey - the (optional) private key
Method Detail

isPrivateKeyAvailable

public boolean isPrivateKeyAvailable()
Returns whether the private key is available

Returns:
whether the private key is available

cipher

@Nonnull
public byte[] cipher(@Nonnull
                             byte[] plainText)
              throws GeneralSecurityException

cipher

Parameters:
plainText - an array of byte.
Returns:
an array of byte.
Throws:
GeneralSecurityException - if any.

decipher

@Nonnull
public byte[] decipher(@Nonnull
                               byte[] bytes)
                throws GeneralSecurityException

decipher

Parameters:
bytes - an array of byte.
Returns:
an array of byte.
Throws:
GeneralSecurityException - if any.

sign

@Nonnull
public Signature sign(@Nonnull
                              byte[] plainText)
               throws GeneralSecurityException

sign

Parameters:
plainText - an array of byte.
Returns:
a Signature object.
Throws:
GeneralSecurityException - if any.

verifySignature

public boolean verifySignature(@Nonnull
                               byte[] plainText,
                               @Nonnull
                               Signature signature)
                        throws GeneralSecurityException

verifySignature

Parameters:
plainText - an array of byte.
signature - a Signature object.
Returns:
a boolean.
Throws:
GeneralSecurityException - if any.

getCertificate

@Nonnull
public X509Certificate getCertificate()
Returns the certificate

Returns:
the certificate

getPrivateKey

@Nonnull
public RSAPrivateKey getPrivateKey()
Returns the private key (if there is one)

Returns:
the private key

readPrivateKey

@Nullable
public static RSAPrivateKey readPrivateKey(@Nullable
                                                    URL privateKeyUrl)
                                    throws IOException,
                                           GeneralSecurityException
Reads a private key form a url

Parameters:
privateKeyUrl - the url containing the private key
Returns:
the read private key
Throws:
IOException - if any.
GeneralSecurityException - if any.

readCertificate

@Nonnull
public static X509Certificate readCertificate(@Nonnull
                                                      URL certificateUrl)
                                       throws IOException,
                                              GeneralSecurityException
Reads the x509 certificate from the given url

Parameters:
certificateUrl - the certificate url
Returns:
the certificate
Throws:
IOException - if any.
GeneralSecurityException - if any.


Copyright © 2012 cedarsoft GmbH. All Rights Reserved.