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
- Direct Known Subclasses:
MultifactorAuthenticationCryptoHelper
Helper to encrypt/decrypt some text
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException when the decrypt key has not worked -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String_configureFilename(Configuration configuration) Configure the file name containing the keyprotected StringRetrieves the file nameprotected String_writeKeyInFile(File file) Will create a new random key based on a sha256 hash of the current time, and write it to a filevoidconfigure(Configuration configuration) Decrypt a string (base64) using the generated keyDecrypt a string (base64) using the selected keyEncrypt (base64) a string using the generated keyEncrypt (base64) a string using the selected keyGet the generated crypto keyMethods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Constructor Details
-
CryptoHelper
public CryptoHelper()
-
-
Method Details
-
configure
- Specified by:
configurein interfaceConfigurable- Throws:
ConfigurationException
-
_configureFilename
Configure the file name containing the key- Parameters:
configuration- the configuration- Returns:
- the file name
- Throws:
ConfigurationException- if an error occurs while configuring the file name
-
_getFilename
Retrieves the file name- Returns:
- the file name
-
decrypt
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
Decrypt a string (base64) using the generated key- Parameters:
encryptedValue- the encrypted value- Returns:
- the decrypted String
-
encrypt
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
Encrypt (base64) a string using the generated key- Parameters:
data- input data- Returns:
- the base64 value of the encrypted data
-
getCryptoKey
Get the generated crypto key- Returns:
- the generated crypto key
-
_writeKeyInFile
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
-