Package com.jbstrap.core.utils
Class CryptoUtils
java.lang.Object
com.jbstrap.core.utils.CryptoUtils
Utility methods for crypto operations.
- Since:
- 4.0
- Author:
- JBStrap
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
aesDecrypt
(String str, String secretKey, String initVector) Decrypts the specified string, using AES 128bit encryptionstatic String
aesEncrypt
(String str, String secretKey, String initVector) Encrypts the specified string, using AES 128bit encryptionstatic String
base64Decrypt
(String str) Decrypts the specified Base64 textstatic String
base64Encrypt
(byte[] data) Encrypts the specified Byte Array, using Base64 encryptionstatic String
base64Encrypt
(String str) Encrypts the specified string using Base64 encryptionstatic String
Encrypts the specified string using MD5
-
Method Details
-
md5
Encrypts the specified string using MD5- Parameters:
input
- The string to be encrypted- Returns:
- The encrypted text as M5 hash. If there was an error during the encryption, it will return with
null
.
-
aesEncrypt
public static String aesEncrypt(String str, String secretKey, String initVector) throws UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException Encrypts the specified string, using AES 128bit encryption- Parameters:
str
- The string to be encryptedsecretKey
- The 128 bit secret keyinitVector
- The 128 bit init vector- Returns:
- The encrypted text
- Throws:
UnsupportedEncodingException
- If the text encoding is not supportedNoSuchPaddingException
- This exception is thrown when a particular padding mechanism is requested but is not available in the environment.NoSuchAlgorithmException
- This exception is thrown when a particular cryptographic algorithm is requested but is not available in the environment.InvalidAlgorithmParameterException
- This is the exception for invalid or inappropriate algorithm parameters.InvalidKeyException
- This is the exception for invalid Keys (invalid encoding, wrong length, uninitialized, etc).BadPaddingException
- If the padding was unsuccessfulIllegalBlockSizeException
- If the length of data provided to a block cipher is incorrect,
-
aesDecrypt
public static String aesDecrypt(String str, String secretKey, String initVector) throws UnsupportedEncodingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException Decrypts the specified string, using AES 128bit encryption- Parameters:
str
- The string to be decryptedsecretKey
- The 128 bit secret keyinitVector
- The 128 bit init vector- Returns:
- The decrypted text
- Throws:
UnsupportedEncodingException
- If the text encoding is not supportedNoSuchPaddingException
- This exception is thrown when a particular padding mechanism is requested but is not available in the environment.NoSuchAlgorithmException
- This exception is thrown when a particular cryptographic algorithm is requested but is not available in the environment.InvalidAlgorithmParameterException
- This is the exception for invalid or inappropriate algorithm parameters.InvalidKeyException
- This is the exception for invalid Keys (invalid encoding, wrong length, uninitialized, etc).BadPaddingException
- If the padding was unsuccessfulIllegalBlockSizeException
- If the length of data provided to a block cipher is incorrect,
-
base64Encrypt
Encrypts the specified string using Base64 encryption- Parameters:
str
- The string to be encrypted- Returns:
- The string, encrypted with Base64
- Throws:
UnsupportedEncodingException
- If the text encoding is not supported
-
base64Encrypt
Encrypts the specified Byte Array, using Base64 encryption- Parameters:
data
- The array to be encrypted- Returns:
- The Base64 string
- Throws:
UnsupportedEncodingException
- If the text encoding is not supported
-
base64Decrypt
Decrypts the specified Base64 text- Parameters:
str
- The Base64 text- Returns:
- The decrypted value
-