org.apache.wicket.util.crypt
Class SunJceCrypt

java.lang.Object
  extended by org.apache.wicket.util.crypt.AbstractCrypt
      extended by 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
static String DEFAULT_CRYPT_METHOD
          Name of the default encryption method
static byte[] SALT
          Salt
 
Constructor Summary
SunJceCrypt()
          Constructor
SunJceCrypt(String cryptMethod)
          Constructor that uses a custom encryption method (cipher).
 
Method Summary
protected  Cipher createCipher(SecretKey key, AlgorithmParameterSpec spec, int mode)
          Creates the Cipher that will do the de-/encryption.
protected  KeySpec createKeySpec()
           
protected  AlgorithmParameterSpec createParameterSpec()
           
protected  byte[] crypt(byte[] input, int mode)
          Crypts the given byte array
protected  SecretKey generateSecretKey()
          Generate the de-/encryption key.
 
Methods inherited from class org.apache.wicket.util.crypt.AbstractCrypt
decryptUrlSafe, encryptUrlSafe, getKey, setKey
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CRYPT_METHOD

public static final 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(String cryptMethod)
Constructor that uses a custom encryption method (cipher). You may need to override createKeySpec() and/or createParameterSpec() for the custom cipher.

Parameters:
cryptMethod - the name of encryption method (the cipher)
Method Detail

crypt

protected byte[] crypt(byte[] input,
                       int mode)
                throws GeneralSecurityException
Crypts the given byte array

Specified by:
crypt in class AbstractCrypt
Parameters:
input - byte array to be encrypted
mode - 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 the Cipher that will do the de-/encryption.

Parameters:
key - the secret key to use
spec - the parameters spec to use
mode - the mode (Cipher.ENCRYPT_MODE or Cipher.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 specified
InvalidKeySpecException - 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


Copyright © 2006–2019 Apache Software Foundation. All rights reserved.