public final class Encryption
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Encryption.EncryptionType
Eases the management of algorithms, modes, and padding
See http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#Cipher for a description
of each.
|
| Constructor and Description |
|---|
Encryption() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
base64Decode(java.lang.String string)
Performs a base 64 decoding on a string
|
static java.lang.String |
base64Decode(java.lang.String string,
java.lang.String encoding)
Performs a base 64 decoding on a string
|
static java.lang.String |
base64Encode(java.lang.String string)
Performs a base 64 encoding on a string
|
static java.lang.String |
base64Encode(java.lang.String string,
java.lang.String encoding)
Performs a base 64 encoding on a string
|
static SecretValue<java.lang.String,byte[],java.lang.Integer> |
decrypt(java.lang.String string,
int encryptionLength,
java.lang.String algorithm,
byte[] key,
byte[] initializationVector)
Decrypts a value
|
static SecretValue<java.lang.String,byte[],java.lang.Integer> |
encrypt(java.lang.String string,
java.lang.String algorithm,
byte[] key,
byte[] initializationVector)
Encrypts a value
|
static <V,K,M> K |
getKey(SecretValue<V,K,M> value)
Gets the key of the SecretValue
|
static <V,K,M> M |
getMeta(SecretValue<V,K,M> value)
Gets the metadata of the SecretValue
|
static <V,K,M> V |
getValue(SecretValue<V,K,M> value)
Gets the value of the SecretValue
|
static <V,K,M> SecretValue<V,K,M> |
newSecretValue(V value,
K key,
M meta)
Creates a new secret value
|
static <V,K,M> SecretValue<V,K,M> |
newSecretValue(V value,
K key,
M meta,
boolean isCallerSensitive)
Creates a new secret value with the approved caller as the caller of this method
|
static <V,K,M> SecretValue<V,K,M> |
newSecretValue(V value,
K key,
M meta,
boolean isCallerSensitive,
java.lang.String approvedCaller)
Creates a new secret value
|
public static SecretValue<java.lang.String,byte[],java.lang.Integer> encrypt(java.lang.String string, java.lang.String algorithm, byte[] key, byte[] initializationVector) throws javax.crypto.NoSuchPaddingException, java.security.NoSuchAlgorithmException, java.security.InvalidAlgorithmParameterException, java.security.InvalidKeyException, javax.crypto.ShortBufferException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
string - The string to encryptalgorithm - The algorithm, mode and padding to usekey - The keyinitializationVector - The initialization vectorgetValue(SecretValue) to get the encrypted value and
getMeta(SecretValue) to get the length of the encryptionjavax.crypto.NoSuchPaddingExceptionjava.security.NoSuchAlgorithmExceptionjava.security.InvalidAlgorithmParameterExceptionjava.security.InvalidKeyExceptionjavax.crypto.ShortBufferExceptionjavax.crypto.IllegalBlockSizeExceptionjavax.crypto.BadPaddingExceptionpublic static SecretValue<java.lang.String,byte[],java.lang.Integer> decrypt(java.lang.String string, int encryptionLength, java.lang.String algorithm, byte[] key, byte[] initializationVector) throws javax.crypto.NoSuchPaddingException, java.security.NoSuchAlgorithmException, java.security.InvalidAlgorithmParameterException, java.security.InvalidKeyException, javax.crypto.ShortBufferException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
string - The encrypted stringencryptionLength - The length of the encryptionalgorithm - The algorithm, mode and padding to usekey - The keyinitializationVector - The initialization vectorgetValue(SecretValue) to get the decrypted value and
getMeta(SecretValue) to get the length of the decryptionjavax.crypto.NoSuchPaddingExceptionjava.security.NoSuchAlgorithmExceptionjava.security.InvalidAlgorithmParameterExceptionjava.security.InvalidKeyExceptionjavax.crypto.ShortBufferExceptionjavax.crypto.IllegalBlockSizeExceptionjavax.crypto.BadPaddingExceptionpublic static <V,K,M> SecretValue<V,K,M> newSecretValue(V value, K key, M meta, boolean isCallerSensitive, java.lang.String approvedCaller)
value - The valuekey - The keymeta - Any metadataisCallerSensitive - Set this to true to limit callers (if supported on the JDK)approvedCaller - The only class allowed to retrieve info from itpublic static <V,K,M> SecretValue<V,K,M> newSecretValue(V value, K key, M meta, boolean isCallerSensitive)
value - The valuekey - The keymeta - Any metadataisCallerSensitive - Set this to true to limit callers (if supported on the JDK)public static <V,K,M> SecretValue<V,K,M> newSecretValue(V value, K key, M meta)
value - The valuekey - The keymeta - Any metadatapublic static <V,K,M> V getValue(SecretValue<V,K,M> value)
value - The SecretValuepublic static <V,K,M> K getKey(SecretValue<V,K,M> value)
value - The SecretValuepublic static <V,K,M> M getMeta(SecretValue<V,K,M> value)
value - The SecretValuepublic static java.lang.String base64Encode(java.lang.String string,
java.lang.String encoding)
throws java.lang.UnsupportedOperationException,
java.io.UnsupportedEncodingException
string - The string to encodeencoding - The encoding of the stringjava.lang.UnsupportedOperationException - Thrown if the sun package isn't found (i.e. when running with OpenJDK)java.io.UnsupportedEncodingExceptionpublic static java.lang.String base64Encode(java.lang.String string)
throws java.lang.UnsupportedOperationException,
java.io.UnsupportedEncodingException
string - The string to encodejava.lang.UnsupportedOperationException - Thrown if the sun package isn't found (i.e. when running with OpenJDK)java.io.UnsupportedEncodingExceptionpublic static java.lang.String base64Decode(java.lang.String string,
java.lang.String encoding)
throws java.lang.UnsupportedOperationException,
java.io.IOException
string - The string to encodeencoding - The encoding of the stringjava.lang.UnsupportedOperationException - Thrown if the sun package isn't found (i.e. when running with OpenJDK)java.io.IOExceptionpublic static java.lang.String base64Decode(java.lang.String string)
throws java.lang.UnsupportedOperationException,
java.io.IOException
string - The string to encodejava.lang.UnsupportedOperationException - Thrown if the sun package isn't found (i.e. when running with OpenJDK)java.io.IOException