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 java.lang.StringDEFAULT_CRYPT_METHODName of the default encryption methodstatic byte[]SALTSalt
-
Constructor Summary
Constructors Constructor Description SunJceCrypt()ConstructorSunJceCrypt(java.lang.String cryptMethod)Constructor that uses a custom encryption method (cipher).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected javax.crypto.CiphercreateCipher(javax.crypto.SecretKey key, java.security.spec.AlgorithmParameterSpec spec, int mode)Creates theCipherthat will do the de-/encryption.protected java.security.spec.KeySpeccreateKeySpec()protected java.security.spec.AlgorithmParameterSpeccreateParameterSpec()protected byte[]crypt(byte[] input, int mode)Crypts the given byte arrayprotected javax.crypto.SecretKeygenerateSecretKey()Generate the de-/encryption key.-
Methods inherited from class org.apache.wicket.util.crypt.AbstractCrypt
decryptUrlSafe, encryptUrlSafe, getKey, setKey
-
-
-
-
Field Detail
-
DEFAULT_CRYPT_METHOD
public static final java.lang.String DEFAULT_CRYPT_METHOD
Name of the default encryption method- See Also:
- Constant Field Values
-
SALT
public static final byte[] SALT
Salt
-
-
Constructor Detail
-
SunJceCrypt
public SunJceCrypt()
Constructor
-
SunJceCrypt
public SunJceCrypt(java.lang.String cryptMethod)
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)
-
-
Method Detail
-
crypt
protected byte[] crypt(byte[] input, int mode) throws java.security.GeneralSecurityExceptionCrypts the given byte array- Specified by:
cryptin classAbstractCrypt- Parameters:
input- byte array to be encryptedmode- crypt mode- Returns:
- the input crypted. Null in case of an error
- Throws:
java.security.GeneralSecurityException
-
createCipher
protected javax.crypto.Cipher createCipher(javax.crypto.SecretKey key, java.security.spec.AlgorithmParameterSpec spec, int mode) throws java.security.GeneralSecurityExceptionCreates theCipherthat will do the de-/encryption.- Parameters:
key- the secret key to usespec- the parameters spec to usemode- the mode (Cipher.ENCRYPT_MODEorCipher.DECRYPT_MODE)- Returns:
- the cipher that will do the de-/encryption
- Throws:
java.security.GeneralSecurityException
-
generateSecretKey
protected javax.crypto.SecretKey generateSecretKey() throws java.security.NoSuchAlgorithmException, java.security.spec.InvalidKeySpecExceptionGenerate 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:
java.security.NoSuchAlgorithmException- unable to find encryption algorithm specifiedjava.security.spec.InvalidKeySpecException- invalid encryption key
-
createParameterSpec
protected java.security.spec.AlgorithmParameterSpec createParameterSpec()
- Returns:
- the parameter spec to be used for the configured crypt method
-
createKeySpec
protected java.security.spec.KeySpec createKeySpec()
- Returns:
- the key spec to be used for the configured crypt method
-
-