Package com.microstrategy.utils.crypto
Class CryptoCipher2
- java.lang.Object
-
- com.microstrategy.utils.crypto.CryptoCipher2
-
public class CryptoCipher2 extends java.lang.Object
This class provides encryption and decryption with AES/GCM/NoPadding. AES/GCM requires the key size shall be at least 128 bits (16 bytes). Currently, for string type key, we will convert it into 16 bytes data as the secret key. If you want to use more key size, you can directly provide the secrete key with byte array. But notices: AES only supports key sizes of 16, 24 or 32 bytes. For any invalid key size, exception will be thrown when callingCryptoCipher2
. For encryption and decryption, we use plain text / cipher text and IV but not use Additional Authentication Data (AAD) as the input data. That is, we won't do any validating for the authentication tag. Currently createInputStream() functionality is not supported, may be fully implemented at later date.
-
-
Field Summary
Fields Modifier and Type Field Description static int
MODE_DECRYPT
static int
MODE_ENCRYPT
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.InputStream
createInputStream(com.microstrategy.utils.crypto.CryptoData stream, int mode)
Not support creating input stream for now.com.microstrategy.utils.crypto.CryptoData
decrypt(com.microstrategy.utils.crypto.CryptoData iCiphertext)
Decrypt the specified data.com.microstrategy.utils.crypto.CryptoData
encrypt(com.microstrategy.utils.crypto.CryptoData iPlainText)
Encrypts the specified data.EnumCipher
getEnumCipher()
Get the encryption cipher.void
setKey(java.lang.String key)
Set secret key with string for crypto cipher.
-
-
-
Field Detail
-
MODE_ENCRYPT
public static final int MODE_ENCRYPT
- See Also:
- Constant Field Values
-
MODE_DECRYPT
public static final int MODE_DECRYPT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getEnumCipher
public EnumCipher getEnumCipher()
Get the encryption cipher.- Returns:
- The encryption cipher.
-
decrypt
public com.microstrategy.utils.crypto.CryptoData decrypt(com.microstrategy.utils.crypto.CryptoData iCiphertext)
Decrypt the specified data.- Parameters:
iCiphertext
- Data to be decrypted- Returns:
- Decrypted data or
null
if the input data is not valid.
-
encrypt
public com.microstrategy.utils.crypto.CryptoData encrypt(com.microstrategy.utils.crypto.CryptoData iPlainText)
Encrypts the specified data. Does not currently support adding additional authenticated data (AAD)- Parameters:
iPlainText
- Data to be encrypted- Returns:
- Encrypted data.
-
createInputStream
public java.io.InputStream createInputStream(com.microstrategy.utils.crypto.CryptoData stream, int mode) throws java.io.IOException, java.security.GeneralSecurityException
Not support creating input stream for now.- Parameters:
stream
-mode
- Encrypt or decrypt mode- Returns:
- Unsupported exception.
- Throws:
java.io.IOException
java.security.GeneralSecurityException
-
setKey
public void setKey(java.lang.String key)
Set secret key with string for crypto cipher.- Parameters:
key
- Secret key
-
-