java.lang.Object
org.apache.wicket.util.crypt.AbstractCrypt
org.apache.wicket.util.crypt.SunJceCrypt
- All Implemented Interfaces:
ICrypt
Provide some simple means to encrypt and decrypt strings such as passwords. The whole
implementation is based around Sun's security providers and uses the PBEWithMD5AndDES method to encrypt and decrypt the
data.
- Author:
- Juergen Donnerstag
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSunJceCrypt
(byte[] salt, int iterationCount) Constructor.SunJceCrypt
(String cryptMethod, byte[] salt, int iterationCount) Constructor that uses a custom encryption method (cipher). -
Method Summary
Modifier and TypeMethodDescriptionprotected Cipher
createCipher
(SecretKey key, AlgorithmParameterSpec spec, int mode) Creates theCipher
that will do the de-/encryption.protected KeySpec
protected AlgorithmParameterSpec
protected byte[]
crypt
(byte[] input, int mode) Crypts the given byte arrayprotected SecretKey
Generate the de-/encryption key.static byte[]
Create a random salt to be used for this crypt.Methods inherited from class org.apache.wicket.util.crypt.AbstractCrypt
decryptUrlSafe, encryptUrlSafe, getKey, setKey
-
Field Details
-
DEFAULT_CRYPT_METHOD
Name of the default encryption method- See Also:
-
-
Constructor Details
-
SunJceCrypt
Constructor.- Parameters:
salt
- salt for encryptioniterationCount
- iteration count
-
SunJceCrypt
Constructor that uses a custom encryption method (cipher). You may need to overridecreateKeySpec()
and/orcreateParameterSpec()
for the custom cipher.- Parameters:
cryptMethod
- the name of encryption method (the cipher)salt
- salt for encryptioniterationCount
- iteration count
-
-
Method Details
-
crypt
Crypts the given byte array- Specified by:
crypt
in classAbstractCrypt
- Parameters:
input
- byte array to be encryptedmode
- crypt mode- Returns:
- the input crypted. Null in case of an error
- Throws:
GeneralSecurityException
-
createCipher
protected Cipher createCipher(SecretKey key, AlgorithmParameterSpec spec, int mode) throws GeneralSecurityException Creates theCipher
that will do the de-/encryption.- Parameters:
key
- the secret key to usespec
- the parameters spec to usemode
- the mode (Cipher.ENCRYPT_MODE
orCipher.DECRYPT_MODE
)- Returns:
- the cipher that will do the de-/encryption
- Throws:
GeneralSecurityException
-
generateSecretKey
Generate the de-/encryption key.Note: if you don't provide your own encryption key, the implementation will use a default. Be aware that this is potential security risk. Thus make sure you always provide your own one.
- Returns:
- secretKey the security key generated
- Throws:
NoSuchAlgorithmException
- unable to find encryption algorithm specifiedInvalidKeySpecException
- invalid encryption key
-
createParameterSpec
- Returns:
- the parameter spec to be used for the configured crypt method
-
createKeySpec
- Returns:
- the key spec to be used for the configured crypt method
-
randomSalt
Create a random salt to be used for this crypt.- Returns:
- salt, always 8 bytes long
-