fabric.common
Class Crypto

java.lang.Object
  extended by fabric.common.Crypto

public final class Crypto
extends java.lang.Object

This is the clearing house for all things crypto.


Field Summary
static java.lang.String ALG_HASH
           
static java.lang.String ALG_PUBLIC_KEY_GEN
           
static java.lang.String ALG_SECRET_CRYPTO
           
static java.lang.String ALG_SECRET_KEY_GEN
           
static java.lang.String ALG_SIGNATURE
           
static int SIZE_PUBLIC_KEY
           
static int SIZE_SECRET_KEY
           
 
Constructor Summary
Crypto()
           
 
Method Summary
static javax.crypto.Cipher cipherInstance(int opmode, byte[] key, byte[] iv)
          Creates an initializes a new Cipher instance with the given parameters.
 java.security.cert.X509Certificate createCertificate(java.lang.String subjectName, java.security.PublicKey subjectKey, java.lang.String issuerName, java.security.PrivateKey issuerKey)
          generates a certificate, signed by the issuer, binding the subject's name to their public key.
static java.security.MessageDigest digestInstance()
           
static void fillIV(byte[] iv)
          Fills an initialization vector with random bytes.
static java.security.KeyPair genKeyPair()
           
static javax.crypto.SecretKey genSecretKey()
           
static byte[] makeIV()
          Creates a new initialization vector.
static java.security.KeyPairGenerator publicKeyGenInstance()
           
static javax.crypto.KeyGenerator secretKeyGenInstance()
           
static java.security.Signature signatureInstance()
           
static boolean validateCertificateChain(java.security.cert.Certificate[] certificateChain, java.security.KeyStore trustStore)
          Validates the given certificate chain against the given trust store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALG_SIGNATURE

public static final java.lang.String ALG_SIGNATURE
See Also:
Constant Field Values

ALG_SECRET_KEY_GEN

public static final java.lang.String ALG_SECRET_KEY_GEN
See Also:
Constant Field Values

SIZE_SECRET_KEY

public static final int SIZE_SECRET_KEY
See Also:
Constant Field Values

ALG_SECRET_CRYPTO

public static final java.lang.String ALG_SECRET_CRYPTO
See Also:
Constant Field Values

ALG_PUBLIC_KEY_GEN

public static final java.lang.String ALG_PUBLIC_KEY_GEN
See Also:
Constant Field Values

SIZE_PUBLIC_KEY

public static final int SIZE_PUBLIC_KEY
See Also:
Constant Field Values

ALG_HASH

public static final java.lang.String ALG_HASH
See Also:
Constant Field Values
Constructor Detail

Crypto

public Crypto()
Method Detail

digestInstance

public static java.security.MessageDigest digestInstance()

signatureInstance

public static java.security.Signature signatureInstance()

secretKeyGenInstance

public static javax.crypto.KeyGenerator secretKeyGenInstance()

genSecretKey

public static javax.crypto.SecretKey genSecretKey()

publicKeyGenInstance

public static java.security.KeyPairGenerator publicKeyGenInstance()

genKeyPair

public static java.security.KeyPair genKeyPair()

fillIV

public static void fillIV(byte[] iv)
Fills an initialization vector with random bytes.


makeIV

public static byte[] makeIV()
Creates a new initialization vector.


cipherInstance

public static javax.crypto.Cipher cipherInstance(int opmode,
                                                 byte[] key,
                                                 byte[] iv)
                                          throws java.security.NoSuchAlgorithmException,
                                                 javax.crypto.NoSuchPaddingException,
                                                 java.security.InvalidKeyException,
                                                 java.security.InvalidAlgorithmParameterException
Creates an initializes a new Cipher instance with the given parameters.

Parameters:
opmode - The mode of operation. One of the mode constants in Cipher.
key - The secret key to use.
iv - The initialization vector to use. For encryption, this should be randomly generated; for decryption, this should match the one used during encryption.
Throws:
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException
java.security.InvalidAlgorithmParameterException

validateCertificateChain

public static boolean validateCertificateChain(java.security.cert.Certificate[] certificateChain,
                                               java.security.KeyStore trustStore)
Validates the given certificate chain against the given trust store.


createCertificate

public java.security.cert.X509Certificate createCertificate(java.lang.String subjectName,
                                                            java.security.PublicKey subjectKey,
                                                            java.lang.String issuerName,
                                                            java.security.PrivateKey issuerKey)
                                                     throws java.security.GeneralSecurityException
generates a certificate, signed by the issuer, binding the subject's name to their public key.

Throws:
java.security.GeneralSecurityException