public final class EncryptionUtil extends Object
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_ASYMMETRIC_ALGORITHM |
static int |
DEFAULT_ASYMMETRIC_KEYSIZE |
static String |
DEFAULT_SYMMETRIC_ALGORITHM |
static int |
DEFAULT_SYMMETRIC_KEYSIZE |
static int |
KEY_TYPE_PRIVATE |
static int |
KEY_TYPE_PUBLIC |
static int |
KEY_TYPE_SECRET |
Modifier and Type | Method and Description |
---|---|
static KeyPair |
createAsymmetricKeys()
Creates a KeyPair with default settings (RSA 512).
|
static KeyPair |
createAsymmetricKeys(int size)
Creates KeyPair with default algorithm (RSA) but given size.
|
static KeyPair |
createAsymmetricKeys(int size,
String algorithm)
Creates new key pair with given algorithm and size.
|
static Key |
createSymmetricKey()
creates symmetric key with default algorithm (AES 128).
|
static Key |
createSymmetricKey(int size)
creates symmetric key with default algorithm (AES) but different key size.
|
static Key |
createSymmetricKey(int size,
String algorithm)
creates symmetric key with given algorithm and key size.
|
static String |
decrypt(String encryptedBytesAsBase64,
Key key,
String transformation)
Decryptes the given result of a previous encrypt (base64 byte string) with the given key and using the given
algorithm.
|
static String |
decryptAsymmetric(String encryptedBytesAsBase64,
Key asymmetricKey)
Default method for asymmetric decryption using the RSA algorithm.
|
static String |
decryptFromHex(String encryptedBytesAsHex,
Key key,
String transformation)
Decrypts the given result of a previous encrypt (hexadecimal byte string) with the given key and using the given
algorithm.
|
static String |
decryptSymmetric(String encryptedBytesAsBase64,
Key symmetricKey)
Default method for symmetric decryption using the AES algorithm.
|
static String |
encrypt(String content,
Key key,
String transformation)
Encrypts the contents of the input string, with the given key and the given algorithm.
|
static String |
encryptAsHex(String content,
Key key,
String transformation)
Encrypts the contents of the input string, with the given key and the given algorithm.
|
static String |
encryptAsymmetric(String content,
Key asymmetricKey)
Default method for symmetric encryption using the RSA algorithm.
|
static String |
encryptSymmetric(String content,
Key symmetricKey)
Default method for symmetric encryption using the AES algorithm.
|
static int |
getKeyType(Key key)
Resolves the key type from the key.
|
static Key |
unwrapAsymmetric(String encryptedKeyBytesAsBase64,
String encryptedKeyAlgorithm,
int encryptedKeyType,
Key asymmetricKey)
Default method for asymmetric unwrapping using the AES algorithm.
|
static Key |
unwrapKey(String encryptedKeyBytesAsBase64,
String encryptedKeyAlgorithm,
int encryptedKeyType,
Key key,
String transformation)
Unwraps a secret key, next to the base64 bytes of the wrapped key you need to know the algorithm used in the key
and the type of the key (e.g.
|
static Key |
unwrapSymmetric(String encryptedKeyBytesAsBase64,
String encryptedKeyAlgorithm,
int encryptedKeyType,
Key symmetricKey)
Default method for symmetric unwrapping using the AES algorithm.
|
static String |
wrapAsymmetric(Key toWrap,
Key asymmetricKey)
Default method for asymmetric key wrapping using the AES algorithm.
|
static String |
wrapKey(Key toWrap,
Key key,
String transformation)
Wraps(encrypts) a secret key to securly transport it over a network.
|
static String |
wrapSymmetric(Key toWrap,
Key symmetricKey)
Default method for symmetric key wrapping using the AES algorithm.
|
public static final String DEFAULT_SYMMETRIC_ALGORITHM
public static final int DEFAULT_SYMMETRIC_KEYSIZE
public static final String DEFAULT_ASYMMETRIC_ALGORITHM
public static final int DEFAULT_ASYMMETRIC_KEYSIZE
public static final int KEY_TYPE_PRIVATE
public static final int KEY_TYPE_PUBLIC
public static final int KEY_TYPE_SECRET
public static int getKeyType(Key key)
key
- a key.public static String encrypt(String content, Key key, String transformation)
content
- input.key
- the key to use.transformation
- the transformation to use.public static String decrypt(String encryptedBytesAsBase64, Key key, String transformation)
encryptedBytesAsBase64
- the encryption bytes.key
- the key to decrypt.transformation
- the algorithm to use.public static String wrapKey(Key toWrap, Key key, String transformation)
toWrap
- the key to wrap.key
- the key used in the wrapping encryption.transformation
- the algorithm.public static Key unwrapKey(String encryptedKeyBytesAsBase64, String encryptedKeyAlgorithm, int encryptedKeyType, Key key, String transformation)
encryptedKeyBytesAsBase64
- the string produced by the wrap method.encryptedKeyAlgorithm
- the algorithm of the encrypted key.encryptedKeyType
- the type of the encrypted Key (e.g. {@link #KEY_TYPE_SECRET)).key
- the key used to decrypt.transformation
- the algorithm used to decrypt the key.public static String encryptSymmetric(String content, Key symmetricKey)
content
- the content to encrypt.symmetricKey
- the symmetric key to use.public static String decryptSymmetric(String encryptedBytesAsBase64, Key symmetricKey)
encryptedBytesAsBase64
- base64 encrypted bytes.symmetricKey
- the symmetric key.public static String wrapSymmetric(Key toWrap, Key symmetricKey)
toWrap
- the Key to encrypt.symmetricKey
- the symmetric key to use.public static Key unwrapSymmetric(String encryptedKeyBytesAsBase64, String encryptedKeyAlgorithm, int encryptedKeyType, Key symmetricKey)
encryptedKeyBytesAsBase64
- the string produced by the wrap method.encryptedKeyAlgorithm
- the algorithm of the encrypted key.encryptedKeyType
- the type of the encrypted Key (e.g. {@link #KEY_TYPE_SECRET)).symmetricKey
- the symmetric key.public static String encryptAsymmetric(String content, Key asymmetricKey)
content
- the content to encrypt.asymmetricKey
- the key to use.public static String decryptAsymmetric(String encryptedBytesAsBase64, Key asymmetricKey)
encryptedBytesAsBase64
- base64 encrypted bytes.asymmetricKey
- the asymmetric key.public static String wrapAsymmetric(Key toWrap, Key asymmetricKey)
toWrap
- the Key to encrypt.asymmetricKey
- the asymmetric key to use.public static Key unwrapAsymmetric(String encryptedKeyBytesAsBase64, String encryptedKeyAlgorithm, int encryptedKeyType, Key asymmetricKey)
encryptedKeyBytesAsBase64
- the string produced by the wrap method.encryptedKeyAlgorithm
- the algorithm of the encrypted key.encryptedKeyType
- the type of the encrypted Key (e.g. {@link #KEY_TYPE_SECRET)).asymmetricKey
- the asymmetric key.public static KeyPair createAsymmetricKeys()
public static KeyPair createAsymmetricKeys(int size)
size
- key size.public static KeyPair createAsymmetricKeys(int size, String algorithm)
size
- key size.algorithm
- algorithm.public static Key createSymmetricKey()
public static Key createSymmetricKey(int size)
public static Key createSymmetricKey(int size, String algorithm)
public static String encryptAsHex(String content, Key key, String transformation)
content
- input.key
- the key to use.transformation
- the transformation to use.public static String decryptFromHex(String encryptedBytesAsHex, Key key, String transformation)
encryptedBytesAsHex
- the encryption bytes.key
- the key to decrypt.transformation
- the algorithm to use.Copyright © 2004–2016 52north.org. All rights reserved.