Package com.sodius.mdw.server.utils
Class EncryptionProvider
- java.lang.Object
-
- com.sodius.mdw.server.utils.EncryptionProvider
-
public abstract class EncryptionProvider extends Object
Provides basic facilities to encrypt and decrypt content. This implementation relies on algorithms provided byjavax.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:
Cipher
-
-
Constructor Summary
Constructors Constructor Description EncryptionProvider()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract String
decrypt(String text)
Deprecated.This method relies on the default platform character encoding.abstract String
decrypt(String text, String charsetName)
De-obfuscate the specified String into the original String that can be interpreted by a human.abstract String
encrypt(String text)
Deprecated.This method relies on the default platform character encoding.abstract String
encrypt(String text, String charsetName)
Obfuscate the specified String content into a String that can hardly be interpreted by a human.static EncryptionProvider
getInstance(String algorithm, String iv)
Instantiates anEncryptionProvider
for the specified cipher algorithm and initialization vector.
-
-
-
Method Detail
-
getInstance
public static EncryptionProvider getInstance(String algorithm, String iv) throws CoreException
Instantiates anEncryptionProvider
for the specified cipher algorithm and initialization vector. If the algorithm isnull
or 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
EncryptionProvider
instance. - 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:
Options.OPTION_ENCRYPTION_SECRET_KEY
-
encrypt
@Deprecated public abstract String encrypt(String text) throws CoreException
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
public abstract String encrypt(String text, String charsetName) throws CoreException
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 public abstract String decrypt(String text) throws CoreException
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(String, String)
-
decrypt
public abstract String decrypt(String text, String charsetName) throws CoreException
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
-
-