public class Encryptor
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Encryptor.CipherMode |
| Constructor and Description |
|---|
Encryptor() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
decrypt(byte[] data,
java.lang.String key)
Decrypts data with key using AES/GCM/NoPadding.
|
static java.lang.String |
decrypt(byte[] data,
java.lang.String key,
byte[] iv)
Decrypts data with key using using AES/GCM/NoPadding.
|
static java.lang.String |
decrypt(java.lang.String data,
java.lang.String key)
Decrypts data with key using AES/GCM/NoPadding.
|
static java.lang.String |
decrypt(java.lang.String data,
java.lang.String key,
byte[] iv)
Decrypts data with key using AES/GCM/NoPadding.
|
static java.lang.String |
decryptBytes(byte[] data,
byte[] key,
byte[] iv)
Decrypts the given bytes using key and IV.
|
static byte[] |
decryptWithoutBase64Encoding(byte[] data,
java.lang.String key)
Decrypts data with key using using AES/GCM/NoPadding.
|
static java.lang.String |
decryptWithRSA(java.security.PrivateKey privateKey,
java.lang.String data,
Encryptor.CipherMode cipherMode)
Returns data decrypted with an RSA private key.
|
static byte[] |
decryptWithRSABytes(java.security.PrivateKey privateKey,
java.lang.String data,
Encryptor.CipherMode cipherMode)
Returns data decrypted with an RSA private key.
|
static byte[] |
decryptWithRSAMultiCipherNodes(java.security.PrivateKey privateKey,
java.lang.String data)
Attempt to decrypt with a RSA private key using different cipher modes:
- RSA_OAEP_SHA256
- then RSA_PKCS1 (legacy)
TODO retire this method when the server only supports RSA_OAEP_SHA256
|
static java.lang.String |
encrypt(java.lang.String data,
java.lang.String key)
Encrypts data with key using AES/GCM/NoPadding.
|
static java.lang.String |
encrypt(java.lang.String data,
java.lang.String key,
byte[] iv)
Encrypts data with key using AES/GCM/NoPadding.
|
static byte[] |
encryptBytes(java.lang.String data,
java.lang.String key)
Encrypts data with key using AES/GCM/NoPadding.
|
static byte[] |
encryptBytes(java.lang.String data,
java.lang.String key,
byte[] iv)
Encrypts data with key using AES/GCM/NoPadding.
|
static byte[] |
encryptWithoutBase64Encoding(byte[] data,
java.lang.String key)
Encrypts data with key using AES/GCM/NoPadding.
|
static byte[] |
encryptWithPublicKey(java.security.PublicKey publicKey,
java.lang.String data,
Encryptor.CipherMode cipherMode) |
static java.lang.String |
encryptWithRSA(java.security.PublicKey publicKey,
java.lang.String data,
Encryptor.CipherMode cipherMode)
Returns data encrypted with an RSA public key.
|
static byte[] |
encryptWithRSABytes(java.security.PublicKey publicKey,
java.lang.String data,
Encryptor.CipherMode cipherMode)
Returns data encrypted with an RSA public key.
|
static java.io.ByteArrayOutputStream |
getByteArrayStreamFromStream(java.io.InputStream stream)
Retrieves data from an InputStream.
|
static javax.crypto.Cipher |
getDecryptingCipher(java.lang.String encryptionKey,
byte[] iv)
Returns initialized cipher for decryption.
|
static javax.crypto.Cipher |
getEncryptingCipher(java.lang.String encryptionKey)
Returns initialized cipher for encryption with an IV automatically generated.
|
static java.lang.String |
getStringFromFile(java.io.File file)
Retrieves data from a File.
|
static java.lang.String |
getStringFromStream(java.io.InputStream stream)
Retrieves data from an InputStream.
|
static java.lang.String |
hash(java.lang.String data,
java.lang.String key)
Return HMAC SHA-256 hash of data using key.
|
static boolean |
isBase64Encoded(java.lang.String key)
Checks if the string is Base64 encoded.
|
public static javax.crypto.Cipher getEncryptingCipher(java.lang.String encryptionKey)
throws java.security.InvalidAlgorithmParameterException,
java.security.InvalidKeyException
encryptionKey - Encryption key.java.security.InvalidAlgorithmParameterExceptionjava.security.InvalidKeyExceptionpublic static javax.crypto.Cipher getDecryptingCipher(java.lang.String encryptionKey,
byte[] iv)
throws java.security.InvalidAlgorithmParameterException,
java.security.InvalidKeyException
encryptionKey - Encryption key.iv - Initialization vector.java.security.InvalidAlgorithmParameterExceptionjava.security.InvalidKeyExceptionpublic static java.lang.String decrypt(java.lang.String data,
java.lang.String key)
data - Data.key - Base64 encoded 256 bit key or null (to leave data unchanged).public static java.lang.String decrypt(byte[] data,
java.lang.String key)
data - Data.key - Key.public static java.lang.String decrypt(java.lang.String data,
java.lang.String key,
byte[] iv)
data - Data.key - Base64 encoded 256 bit key or null (to leave data unchanged).iv - Initialization vector.public static java.lang.String decrypt(byte[] data,
java.lang.String key,
byte[] iv)
data - Data.key - Key.iv - Initialization vector.public static byte[] decryptWithoutBase64Encoding(byte[] data,
java.lang.String key)
data - Data.key - Key.public static java.lang.String encrypt(java.lang.String data,
java.lang.String key)
data - Data.key - Base64 encoded 256 bit key or null (to leave data unchanged).public static java.lang.String encrypt(java.lang.String data,
java.lang.String key,
byte[] iv)
data - Data.key - Base64 encoded 256 bit key or null (to leave data unchanged).iv - Initialization vector.public static byte[] encryptBytes(java.lang.String data,
java.lang.String key)
data - Data.key - Key.public static byte[] encryptBytes(java.lang.String data,
java.lang.String key,
byte[] iv)
data - Data.key - Key.iv - Initialization vector.public static byte[] encryptWithoutBase64Encoding(byte[] data,
java.lang.String key)
data - Data.key - Key.public static boolean isBase64Encoded(java.lang.String key)
key - String.public static java.lang.String hash(java.lang.String data,
java.lang.String key)
data - Data.key - Key.public static java.lang.String encryptWithRSA(java.security.PublicKey publicKey,
java.lang.String data,
Encryptor.CipherMode cipherMode)
publicKey - RSA public key.data - Data to be encrypted.cipherMode - Cipher mode.public static byte[] encryptWithRSABytes(java.security.PublicKey publicKey,
java.lang.String data,
Encryptor.CipherMode cipherMode)
publicKey - RSA public key.data - Data to be encrypted.cipherMode - Cipher mode.public static java.lang.String decryptWithRSA(java.security.PrivateKey privateKey,
java.lang.String data,
Encryptor.CipherMode cipherMode)
privateKey - RSA private key.data - Data to be decrypted.cipherMode - Cipher mode.public static byte[] decryptWithRSABytes(java.security.PrivateKey privateKey,
java.lang.String data,
Encryptor.CipherMode cipherMode)
privateKey - RSA private key.data - Data to be decrypted.cipherMode - Ciper mode.public static byte[] decryptWithRSAMultiCipherNodes(java.security.PrivateKey privateKey,
java.lang.String data)
privateKey - RSA private key.data - Data to be decrypted.public static java.lang.String decryptBytes(byte[] data,
byte[] key,
byte[] iv)
data - Data bytes.key - Key bytes.iv - Initialization vector bytes.public static java.lang.String getStringFromStream(java.io.InputStream stream)
throws java.io.IOException
stream - InputStream data.java.io.IOException - Provide log details of this exception in a catch with specifics
about the operation this method was called for.public static java.io.ByteArrayOutputStream getByteArrayStreamFromStream(java.io.InputStream stream)
throws java.io.IOException
stream - InputStream data.java.io.IOException - Provide log details of this exception in a catch with specifics
about the operation this method was called for.public static java.lang.String getStringFromFile(java.io.File file)
throws java.io.IOException
file - File object.java.io.IOException - Provide log details of this exception in a catch with specifics
about the operation this method was called for.public static byte[] encryptWithPublicKey(java.security.PublicKey publicKey,
java.lang.String data,
Encryptor.CipherMode cipherMode)