public class CryptoHelper extends AbstractLogEnabled implements Component
| Modifier and Type | Field and Description | 
|---|---|
| private String | _cryptoKey | 
| private static String | CHARSET | 
| private static String | CIPHER_ALGORITHM | 
| private static String | KEY_ALGORITHM | 
| private static String | PASS_HASH_ALGORITHM | 
| static String | ROLEAvalon Role | 
| Constructor and Description | 
|---|
| CryptoHelper() | 
| Modifier and Type | Method and Description | 
|---|---|
| private Cipher | _buildCipher(String password,
            int mode) | 
| private Key | _buildKey(String password) | 
| private String | _writeKeyInFile(File file)Will create a new random key based on a sha256 hash of the current time, and write it to a file | 
| String | decrypt(String encryptedValue)Decrypt a string (base64) using the generated key | 
| String | decrypt(String encryptedValue,
       String key)Decrypt a string (base64) using the selected key | 
| String | encrypt(String data)Encrypt (base64) a string using the generated key | 
| String | encrypt(String data,
       String key)Encrypt (base64) a string using the selected key | 
| String | getCryptoKey()Get the generated crypto key | 
getLogger, setLoggerprivate static final String CHARSET
private static final String CIPHER_ALGORITHM
private static final String KEY_ALGORITHM
private static final String PASS_HASH_ALGORITHM
private String _cryptoKey
public CryptoHelper()
public String decrypt(String encryptedValue, String key)
encryptedValue - the encrypted valuekey - The key used to decrypt valuepublic String decrypt(String encryptedValue)
encryptedValue - the encrypted valuepublic String encrypt(String data, String key)
data - input datakey - the key used to encryptpublic String encrypt(String data)
data - input datapublic String getCryptoKey()
private String _writeKeyInFile(File file) throws IOException
file - file where to writeIOException - if something went wrong when writting the fileprivate Cipher _buildCipher(String password, int mode) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, UnsupportedEncodingException
private Key _buildKey(String password) throws NoSuchAlgorithmException, UnsupportedEncodingException