Package com.microstrategy.utils
Class EncryptionUtil
- java.lang.Object
-
- com.microstrategy.utils.EncryptionUtil
-
public class EncryptionUtil extends java.lang.Object
Utility class for Encryption
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
MD5_ALGORITHM
static java.lang.String
SHA1_ALGORITHM
static java.lang.String
SHA256_ALGORITHM
static java.lang.String
SUPPORT_SEAMLESS_LOGIN_COMPATIBILITY
-
Constructor Summary
Constructors Constructor Description EncryptionUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]
decrypt(java.lang.String base64EncryptedStringValue, java.lang.String key)
static java.lang.String
decryptToString(java.lang.String base64EncryptedStringValue, java.lang.String key)
static byte[]
encrypt(java.lang.String dataToEncrypt, java.lang.String key)
Encrypts the given datastatic java.lang.String
encryptToBase64String(java.lang.String dataToEncrypt, java.lang.String key)
Encrypts and returns base64 encoded Stringstatic java.lang.String
printHexBinary(byte[] data)
Converts byte[] to hex String Copy of javax.xml.bind.DatatypeConverter (Lower case letter though)static java.lang.String
sha256Hex(java.lang.String data)
Calculates the SHA-256 digest and returns the value as a hex string.
-
-
-
Field Detail
-
MD5_ALGORITHM
public static java.lang.String MD5_ALGORITHM
-
SHA256_ALGORITHM
public static java.lang.String SHA256_ALGORITHM
-
SHA1_ALGORITHM
public static java.lang.String SHA1_ALGORITHM
-
SUPPORT_SEAMLESS_LOGIN_COMPATIBILITY
public static java.lang.String SUPPORT_SEAMLESS_LOGIN_COMPATIBILITY
-
-
Method Detail
-
encrypt
public static byte[] encrypt(java.lang.String dataToEncrypt, java.lang.String key) throws java.security.NoSuchAlgorithmException, javax.crypto.NoSuchPaddingException, java.security.InvalidKeyException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
Encrypts the given data- Parameters:
dataToEncrypt
-key
-- Returns:
- Throws:
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException
-
encryptToBase64String
public static java.lang.String encryptToBase64String(java.lang.String dataToEncrypt, java.lang.String key) throws java.security.NoSuchAlgorithmException, javax.crypto.NoSuchPaddingException, java.security.InvalidKeyException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
Encrypts and returns base64 encoded String- Parameters:
dataToEncrypt
-key
-- Returns:
- Throws:
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException
-
decrypt
public static byte[] decrypt(java.lang.String base64EncryptedStringValue, java.lang.String key) throws java.security.NoSuchAlgorithmException, javax.crypto.NoSuchPaddingException, java.security.InvalidKeyException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
- Parameters:
base64EncryptedStringValue
- Previously Encrypted base64EncodedStringkey
-- Returns:
- Throws:
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException
-
decryptToString
public static java.lang.String decryptToString(java.lang.String base64EncryptedStringValue, java.lang.String key) throws java.security.NoSuchAlgorithmException, javax.crypto.NoSuchPaddingException, java.security.InvalidKeyException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException
- Parameters:
base64EncryptedStringValue
- Previously Encrypted base64EncodedStringhashKey
-keySpecAlgorithm
- ex. AES, DES etc.cipherAlgorithm
- ex. "AES/ECB/PKCS5Padding". Refer to https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html Limited modes & padding supported( as for ex. CBC mode requires additional parameters to be provided. and not supported here)- Returns:
- Throws:
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException
-
printHexBinary
public static java.lang.String printHexBinary(byte[] data)
Converts byte[] to hex String Copy of javax.xml.bind.DatatypeConverter (Lower case letter though)- Parameters:
data
-- Returns:
-
sha256Hex
public static java.lang.String sha256Hex(java.lang.String data)
Calculates the SHA-256 digest and returns the value as a hex string.- Parameters:
data
- Data to digest- Returns:
- SHA-256 digest as a hex string
-
-