Message Security Layer (MSL)

com.netflix.msl.crypto
Class CryptoCache

java.lang.Object
  extended by com.netflix.msl.crypto.CryptoCache

public class CryptoCache
extends Object

The crypto context cache provides a thread-local cache of cipher and signature objects.


Field Summary
private static ThreadLocal<Map<String,Cipher>> cipherCache
          Cache of transforms onto ciphers.
private static ThreadLocal<Map<String,MessageDigest>> digestCache
          Cache of algorithms onto message digests.
private static ThreadLocal<Map<String,KeyAgreement>> keyAgreementCache
          Cache of algorithms onto key agreements.
private static ThreadLocal<Map<String,KeyFactory>> keyFactoryCache
          Cache of algorithms onto key factories.
private static ThreadLocal<Map<String,KeyPairGenerator>> keyPairGeneratorCache
          Cache of algorithms onto key pair generators.
private static ThreadLocal<Map<String,Mac>> macCache
          Cache of algorithms onto MACs.
private static ThreadLocal<Map<String,Signature>> signatureCache
          Cache of algorithms onto signatures.
 
Constructor Summary
CryptoCache()
           
 
Method Summary
static Cipher getCipher(String transform)
          Returns a Cipher object that implements the specified transform.
static KeyAgreement getKeyAgreement(String algorithm)
          Returns a KeyAgreement object that implements the specified algorithm.
static KeyFactory getKeyFactory(String algorithm)
          Returns a KeyFactory object that implements the specified algorithm.
static KeyPairGenerator getKeyPairGenerator(String algorithm)
          Returns a KeyPairGenerator object that implements the specified algorithm.
static Mac getMac(String algorithm)
          Returns a Mac object that implements the specified algorithm.
static MessageDigest getMessageDigest(String algorithm)
          Returns a MessageDigest object that implements the specified algorithm.
static Signature getSignature(String algorithm)
          Returns a Signature object that implements the specified algorithm.
static void resetCipher(String transform)
          Resets the Cipher object that implements the specified transform.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cipherCache

private static ThreadLocal<Map<String,Cipher>> cipherCache
Cache of transforms onto ciphers.


signatureCache

private static ThreadLocal<Map<String,Signature>> signatureCache
Cache of algorithms onto signatures.


digestCache

private static ThreadLocal<Map<String,MessageDigest>> digestCache
Cache of algorithms onto message digests.


macCache

private static ThreadLocal<Map<String,Mac>> macCache
Cache of algorithms onto MACs.


keyFactoryCache

private static ThreadLocal<Map<String,KeyFactory>> keyFactoryCache
Cache of algorithms onto key factories.


keyAgreementCache

private static ThreadLocal<Map<String,KeyAgreement>> keyAgreementCache
Cache of algorithms onto key agreements.


keyPairGeneratorCache

private static ThreadLocal<Map<String,KeyPairGenerator>> keyPairGeneratorCache
Cache of algorithms onto key pair generators.

Constructor Detail

CryptoCache

public CryptoCache()
Method Detail

getCipher

public static Cipher getCipher(String transform)
                        throws NoSuchAlgorithmException,
                               NoSuchPaddingException
Returns a Cipher object that implements the specified transform.

Parameters:
transform - encrypt/decrypt transform.
Returns:
the cipher instance.
Throws:
NoSuchAlgorithmException - if transformation is null, empty, in an invalid format, or if no Provider supports a CipherSpi implementation for the specified algorithm.
NoSuchPaddingException - if transformation contains a padding scheme that is not available.
See Also:
resetCipher(String)

resetCipher

public static void resetCipher(String transform)
Resets the Cipher object that implements the specified transform. This method must be called if the cipher throws an exception to ensure a clean cipher is returned from the next call to getCipher(String).

Parameters:
transform - encrypt/decrypt transform.
See Also:
getCipher(String)

getSignature

public static Signature getSignature(String algorithm)
                              throws NoSuchAlgorithmException
Returns a Signature object that implements the specified algorithm.

Parameters:
algorithm - the sign/verify algorithm.
Returns:
the signature instance.
Throws:
NoSuchAlgorithmException - if no Provider supports a Signature implementation for the specified algorithm.

getMessageDigest

public static MessageDigest getMessageDigest(String algorithm)
                                      throws NoSuchAlgorithmException
Returns a MessageDigest object that implements the specified algorithm.

Parameters:
algorithm - the digest algorithm.
Returns:
the message digest instance.
Throws:
NoSuchAlgorithmException - if no Provider supports a MessageDigest implementation for the specified algorithm.

getMac

public static Mac getMac(String algorithm)
                  throws NoSuchAlgorithmException
Returns a Mac object that implements the specified algorithm.

Parameters:
algorithm - the MAC algorithm.
Returns:
the MAC instance.
Throws:
NoSuchAlgorithmException - if no Provider supports a Mac implementation for the specified algorithm.

getKeyFactory

public static KeyFactory getKeyFactory(String algorithm)
                                throws NoSuchAlgorithmException
Returns a KeyFactory object that implements the specified algorithm.

Parameters:
algorithm - the key factory algorithm.
Returns:
the key factory instance.
Throws:
NoSuchAlgorithmException - if no Provider supports a KeyFactory implementation for the specified algorithm.

getKeyAgreement

public static KeyAgreement getKeyAgreement(String algorithm)
                                    throws NoSuchAlgorithmException
Returns a KeyAgreement object that implements the specified algorithm.

Parameters:
algorithm - the key agreement algorithm.
Returns:
the key agreement instance.
Throws:
NoSuchAlgorithmException - if no Provider supports a KeyAgreement implementation for the specified algorithm.

getKeyPairGenerator

public static KeyPairGenerator getKeyPairGenerator(String algorithm)
                                            throws NoSuchAlgorithmException
Returns a KeyPairGenerator object that implements the specified algorithm.

Parameters:
algorithm - the key pair generator algorithm.
Returns:
the key pair generator instance.
Throws:
NoSuchAlgorithmException - if no Provider supports a KeyPairGenerator implementation for the specified algorithm.

Message Security Layer (MSL)

Copyright © 2014 Netflix, Inc. All Rights Reserved.