Package org.apache.wicket.util.crypt
Class SunJceCrypt
- java.lang.Object
-
- org.apache.wicket.util.crypt.AbstractCrypt
-
- org.apache.wicket.util.crypt.SunJceCrypt
-
- All Implemented Interfaces:
ICrypt
public class SunJceCrypt extends AbstractCrypt
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 Modifier and Type Field Description static String
DEFAULT_CRYPT_METHOD
Name of the default encryption methodstatic byte[]
SALT
Deprecated.TODO remove in Wicket 10
-
Constructor Summary
Constructors Constructor Description SunJceCrypt()
Deprecated, for removal: This API element is subject to removal in a future version.TODO remove in Wicket 10SunJceCrypt(byte[] salt, int iterationCount)
Constructor.SunJceCrypt(String cryptMethod)
Deprecated, for removal: This API element is subject to removal in a future version.TODO remove in Wicket 10SunJceCrypt(String cryptMethod, byte[] salt, int iterationCount)
Constructor that uses a custom encryption method (cipher).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Cipher
createCipher(SecretKey key, AlgorithmParameterSpec spec, int mode)
Creates theCipher
that will do the de-/encryption.protected KeySpec
createKeySpec()
protected AlgorithmParameterSpec
createParameterSpec()
protected byte[]
crypt(byte[] input, int mode)
Crypts the given byte arrayprotected SecretKey
generateSecretKey()
Generate the de-/encryption key.static byte[]
randomSalt()
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 Detail
-
DEFAULT_CRYPT_METHOD
public static final String DEFAULT_CRYPT_METHOD
Name of the default encryption method- See Also:
- Constant Field Values
-
SALT
@Deprecated public static final byte[] SALT
Deprecated.TODO remove in Wicket 10Default salt.
-
-
Constructor Detail
-
SunJceCrypt
@Deprecated(forRemoval=true) public SunJceCrypt()
Deprecated, for removal: This API element is subject to removal in a future version.TODO remove in Wicket 10Constructor
-
SunJceCrypt
public SunJceCrypt(byte[] salt, int iterationCount)
Constructor.- Parameters:
salt
- salt for encryptioniterationCount
- iteration count
-
SunJceCrypt
@Deprecated(forRemoval=true) public SunJceCrypt(String cryptMethod)
Deprecated, for removal: This API element is subject to removal in a future version.TODO remove in Wicket 10Constructor
-
SunJceCrypt
public SunJceCrypt(String cryptMethod, byte[] salt, int iterationCount)
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 Detail
-
crypt
protected byte[] crypt(byte[] input, int mode) throws GeneralSecurityException
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
protected SecretKey generateSecretKey() throws NoSuchAlgorithmException, InvalidKeySpecException
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
protected AlgorithmParameterSpec createParameterSpec()
- Returns:
- the parameter spec to be used for the configured crypt method
-
createKeySpec
protected KeySpec createKeySpec()
- Returns:
- the key spec to be used for the configured crypt method
-
randomSalt
public static byte[] randomSalt()
Create a random salt to be used for this crypt.- Returns:
- salt, always 8 bytes long
-
-