Class CryptoHelper
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.messagingconnector.CryptoHelper
-
- All Implemented Interfaces:
LogEnabled
,Component
public class CryptoHelper extends AbstractLogEnabled implements Component
Helper to encrypt/decrypt some text
-
-
Field Summary
Fields Modifier and Type Field 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
ROLE
Avalon Role
-
Constructor Summary
Constructors Constructor Description CryptoHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 fileString
decrypt(String encryptedValue)
Decrypt a string (base64) using the generated keyString
decrypt(String encryptedValue, String key)
Decrypt a string (base64) using the selected keyString
encrypt(String data)
Encrypt (base64) a string using the generated keyString
encrypt(String data, String key)
Encrypt (base64) a string using the selected keyString
getCryptoKey()
Get the generated crypto key-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
CHARSET
private static final String CHARSET
- See Also:
- Constant Field Values
-
CIPHER_ALGORITHM
private static final String CIPHER_ALGORITHM
- See Also:
- Constant Field Values
-
KEY_ALGORITHM
private static final String KEY_ALGORITHM
- See Also:
- Constant Field Values
-
PASS_HASH_ALGORITHM
private static final String PASS_HASH_ALGORITHM
- See Also:
- Constant Field Values
-
_cryptoKey
private String _cryptoKey
-
-
Constructor Detail
-
CryptoHelper
public CryptoHelper()
-
-
Method Detail
-
decrypt
public String decrypt(String encryptedValue, String key)
Decrypt a string (base64) using the selected key- Parameters:
encryptedValue
- the encrypted valuekey
- The key used to decrypt value- Returns:
- the decrypted String
-
decrypt
public String decrypt(String encryptedValue)
Decrypt a string (base64) using the generated key- Parameters:
encryptedValue
- the encrypted value- Returns:
- the decrypted String
-
encrypt
public String encrypt(String data, String key)
Encrypt (base64) a string using the selected key- Parameters:
data
- input datakey
- the key used to encrypt- Returns:
- the base64 value of the encrypted data
-
encrypt
public String encrypt(String data)
Encrypt (base64) a string using the generated key- Parameters:
data
- input data- Returns:
- the base64 value of the encrypted data
-
getCryptoKey
public String getCryptoKey()
Get the generated crypto key- Returns:
- the generated crypto key
-
_writeKeyInFile
private String _writeKeyInFile(File file) throws IOException
Will create a new random key based on a sha256 hash of the current time, and write it to a file- Parameters:
file
- file where to write- Returns:
- the generated password
- Throws:
IOException
- if something went wrong when writting the file
-
_buildCipher
private Cipher _buildCipher(String password, int mode) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, UnsupportedEncodingException
-
_buildKey
private Key _buildKey(String password) throws NoSuchAlgorithmException, UnsupportedEncodingException
-
-