org.xwiki.crypto.x509.internal
Class DefaultXWikiX509KeyPair

java.lang.Object
  extended by org.xwiki.crypto.x509.internal.DefaultXWikiX509KeyPair
All Implemented Interfaces:
java.io.Serializable, XWikiX509KeyPair

public class DefaultXWikiX509KeyPair
extends java.lang.Object
implements XWikiX509KeyPair

Wrapper for storing a PrivateKey and the corresponding XWikiX509Certificate.

Since:
2.5M1
Version:
$Id$
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.xwiki.crypto.x509.XWikiX509KeyPair
BASE64_FOOTER, BASE64_HEADER
 
Constructor Summary
DefaultXWikiX509KeyPair(java.security.cert.X509Certificate certificate, java.security.PrivateKey key, java.lang.String password, PasswordCryptoService passwordCryptoService)
          Create new XWikiX509KeyPair.
 
Method Summary
 boolean equals(java.lang.Object obj)
          
static XWikiX509KeyPair fromBase64String(byte[] keyPairAsBytes)
          Deserialize an instance of XWikiX509KeyPair from a byte array, opposite of serialize().
static XWikiX509KeyPair fromBase64String(java.lang.String keyPairAsBase64)
          Deserialize an instance of XWikiX509KeyPair from a base-64 String, opposite of serializeAsBase64().
 XWikiX509Certificate getCertificate()
          Get the user's certificate.
 java.lang.String getFingerprint()
          
 java.security.PrivateKey getPrivateKey(java.lang.String password)
          Get the private key from the key pair.
 java.security.PublicKey getPublicKey()
          
 int hashCode()
          
 byte[] serialize()
          
 java.lang.String serializeAsBase64()
          
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultXWikiX509KeyPair

public DefaultXWikiX509KeyPair(java.security.cert.X509Certificate certificate,
                               java.security.PrivateKey key,
                               java.lang.String password,
                               PasswordCryptoService passwordCryptoService)
                        throws java.security.GeneralSecurityException
Create new XWikiX509KeyPair.

Parameters:
certificate - a certificate matching the private key, this will be stored unencrypted.
key - the private key to use, this will be password encrypted.
password - the password to require if a user wants to extract the private key.
passwordCryptoService - the service to use for encrypting the private key so this object can safely be serialized without allowing the private key to be read from the database.
Throws:
java.security.GeneralSecurityException - if encrypting the private key fails.
Method Detail

fromBase64String

public static XWikiX509KeyPair fromBase64String(java.lang.String keyPairAsBase64)
                                         throws java.io.IOException,
                                                java.lang.ClassNotFoundException,
                                                java.security.cert.CertificateException
Deserialize an instance of XWikiX509KeyPair from a base-64 String, opposite of serializeAsBase64().

Parameters:
keyPairAsBase64 - a base-64 String as produced by serializeAsBase64().
Returns:
some type of XWikiX509KeyPair depending on the type which was serialized.
Throws:
java.io.IOException - if something goes wrong within the serialization framework.
java.lang.ClassNotFoundException - if the object which was serialized is not available now.
java.security.cert.CertificateException - if deserialization of the certificate fails.

fromBase64String

public static XWikiX509KeyPair fromBase64String(byte[] keyPairAsBytes)
                                         throws java.io.IOException,
                                                java.lang.ClassNotFoundException,
                                                java.security.cert.CertificateException
Deserialize an instance of XWikiX509KeyPair from a byte array, opposite of serialize().

Parameters:
keyPairAsBytes - an array of bytes as produced by serialize().
Returns:
some type of XWikiX509KeyPair depending on the type which was serialized.
Throws:
java.io.IOException - if something goes wrong within the serialization framework.
java.lang.ClassNotFoundException - if the object which was serialized is not available now.
java.security.cert.CertificateException - if deserialization of the certificate fails.

serializeAsBase64

public java.lang.String serializeAsBase64()
                                   throws java.io.IOException

Specified by:
serializeAsBase64 in interface XWikiX509KeyPair
Returns:
this key pair XWikiX509KeyPair.serialize()d and converted to a base-64 encoded String.
Throws:
java.io.IOException - if something goes wrong within the serialization framework.
See Also:
XWikiX509KeyPair.serializeAsBase64()

serialize

public byte[] serialize()
                 throws java.io.IOException

Specified by:
serialize in interface XWikiX509KeyPair
Returns:
this key pair as a byte array, the private key will remain password encrypted as it is in memory.
Throws:
java.io.IOException - if something goes wrong within the serialization framework.
See Also:
XWikiX509KeyPair.serialize()

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

equals

public boolean equals(java.lang.Object obj)

Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

getCertificate

public XWikiX509Certificate getCertificate()
Get the user's certificate. May throw a RuntimeException if the key pair was deserialized directly using Java deserialization methods without checking that the certificate can be deserialized.

Specified by:
getCertificate in interface XWikiX509KeyPair
Returns:
the user's certificate
See Also:
XWikiX509KeyPair.getCertificate()

getPublicKey

public java.security.PublicKey getPublicKey()

Specified by:
getPublicKey in interface XWikiX509KeyPair
Returns:
the public key
See Also:
XWikiX509KeyPair.getPublicKey()

getPrivateKey

public java.security.PrivateKey getPrivateKey(java.lang.String password)
                                       throws java.security.GeneralSecurityException
Get the private key from the key pair.

Specified by:
getPrivateKey in interface XWikiX509KeyPair
Parameters:
password - the password needed to decrypt the private key.
Returns:
the private key or null if the password is incorrect.
Throws:
java.security.GeneralSecurityException - if the private key cannot be decrypted.
See Also:
XWikiX509KeyPair.getPrivateKey(java.lang.String)

getFingerprint

public java.lang.String getFingerprint()

Specified by:
getFingerprint in interface XWikiX509KeyPair
Returns:
certificate fingerprint
See Also:
XWikiX509KeyPair.getFingerprint()


Copyright © 2004-2011 XWiki. All Rights Reserved.