Package org.ametys.core.util
Class CryptoHelper
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.core.util.CryptoHelper
-
- All Implemented Interfaces:
LogEnabled
,Component
,Configurable
public class CryptoHelper extends AbstractLogEnabled implements Component, Configurable
Helper to encrypt/decrypt some text
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CryptoHelper.WrongKeyException
Exception when the decrypt key has not worked
-
Constructor Summary
Constructors Constructor Description CryptoHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configure(Configuration configuration)
String
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
-
-
-
-
Constructor Detail
-
CryptoHelper
public CryptoHelper()
-
-
Method Detail
-
configure
public void configure(Configuration configuration) throws ConfigurationException
- Specified by:
configure
in interfaceConfigurable
- Throws:
ConfigurationException
-
decrypt
public String decrypt(String encryptedValue, String key) throws CryptoHelper.WrongKeyException
Decrypt a string (base64) using the selected key- Parameters:
encryptedValue
- the encrypted valuekey
- The key used to decrypt value- Returns:
- the decrypted String
- Throws:
CryptoHelper.WrongKeyException
- If the key is not the right one
-
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
-
-