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_cryptoKeyprivate static StringCHARSETprivate static StringCIPHER_ALGORITHMprivate static StringKEY_ALGORITHMprivate static StringPASS_HASH_ALGORITHMstatic StringROLEAvalon 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 fileStringdecrypt(String encryptedValue)Decrypt a string (base64) using the generated keyStringdecrypt(String encryptedValue, String key)Decrypt a string (base64) using the selected keyStringencrypt(String data)Encrypt (base64) a string using the generated keyStringencrypt(String data, String key)Encrypt (base64) a string using the selected keyStringgetCryptoKey()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
-
-