Package com.sodius.mdw.server.utils
Class EncryptionProvider
java.lang.Object
com.sodius.mdw.server.utils.EncryptionProvider
Provides basic facilities to encrypt and decrypt content.
This implementation relies on algorithms provided by
javax.crypto.Cipher.
Note that clients are strongly recommended to use HTTPS instead of HTTP to secure communications, in which case this class is useless.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract StringDeprecated.This method relies on the default platform character encoding.abstract StringDe-obfuscate the specified String into the original String that can be interpreted by a human.abstract StringDeprecated.This method relies on the default platform character encoding.abstract StringObfuscate the specified String content into a String that can hardly be interpreted by a human.static EncryptionProvidergetInstance(String algorithm, String iv) Instantiates anEncryptionProviderfor the specified cipher algorithm and initialization vector.
-
Constructor Details
-
EncryptionProvider
public EncryptionProvider()
-
-
Method Details
-
getInstance
Instantiates anEncryptionProviderfor the specified cipher algorithm and initialization vector. If the algorithm isnullor an empty String, the returned instance will not encrypt nor decrypt provided content.- Parameters:
algorithm- the cipher algorithm.iv- the cipher initialization vector.- Returns:
- a new
EncryptionProviderinstance. - Throws:
CoreException- if the specified algorithm cannot be used or if the encryption secret key is not set as servlet context parameter or a System property.- See Also:
-
encrypt
Deprecated.This method relies on the default platform character encoding. Clients are advised to use the encrypt(String, String) method that allows specifying an explicit charset.Obfuscate the specified String content into a String that can hardly be interpreted by a human.- Parameters:
text- the text to encrypt.- Returns:
- the encrypted text.
- Throws:
CoreException- if the encryption algorithm cannot be used.
-
encrypt
Obfuscate the specified String content into a String that can hardly be interpreted by a human.- Parameters:
text- the text to encrypt.charsetName- the character encoding used to convert characters to bytes ("UTF-8"is recommended).- Returns:
- the encrypted text.
- Throws:
CoreException- if the encryption algorithm cannot be used.- Since:
- 2.1.3
-
decrypt
Deprecated.This method relies on the default platform character encoding. Clients are advised to use the decrypt(String, String) method that allows specifying an explicit charset.De-obfuscate the specified String into the original String that can be interpreted by a human.- Parameters:
text- the text to decrypt.- Returns:
- the decrypted text.
- Throws:
CoreException- if the encryption algorithm cannot be used.- See Also:
-
decrypt
De-obfuscate the specified String into the original String that can be interpreted by a human.- Parameters:
text- the text to decrypt.charsetName- the character encoding used to convert decrypted bytes to characters ("UTF-8"is recommended).- Returns:
- the decrypted text.
- Throws:
CoreException- if the encryption algorithm cannot be used or the charset is unknown.- Since:
- 2.1.3
-