SPT Core API

com.sptci.util
Class TripleDESEncrypt

java.lang.Object
  extended by com.sptci.util.Encrypt
      extended by com.sptci.util.TripleDESEncrypt

public class TripleDESEncrypt
extends Encrypt

A utility class used to implement Triple DES (3DES) encryption and decryption of strings.

The following shows sample use of this class:

   import com.sptci.util.TripleDESEncrypt;

     ...
     TripleDESEncrypt des = new TripleDESEncrypt();
     String secret = "my secret value";
     String key = "my secret key";
     byte[] encrypted = des.encrypt( key, secret );
     ...
     String mysecret = des.decrypt( key, encrypted );
 

© Copyright 2007 Sans Pareil Technologies, Inc.

Version:
$Id: TripleDESEncrypt.java 4553 2008-12-24 10:34:16Z rakesh $
Author:
Rakesh Vidyadharan 2007-09-14

Field Summary
protected static String ALGORITHM
          The encryption algorithm to use to encrypt strings.
protected static String SCHEME
          The encryption scheme to use to encrypt strings}.
 
Fields inherited from class com.sptci.util.Encrypt
ENCODING, KEY_LENGTH, keyLength
 
Constructor Summary
TripleDESEncrypt()
          Default constructor.
 
Method Summary
protected  byte[] crypt(String key, byte[] value, int mode)
          Encrypt/decrypt the specified value using the specified key.
 
Methods inherited from class com.sptci.util.Encrypt
decrypt, encrypt, getKey, handleException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALGORITHM

protected static final String ALGORITHM
The encryption algorithm to use to encrypt strings. "DESede"

See Also:
Constant Field Values

SCHEME

protected static final String SCHEME
The encryption scheme to use to encrypt strings}. "DESede"

See Also:
Constant Field Values
Constructor Detail

TripleDESEncrypt

public TripleDESEncrypt()
Default constructor. Create a new instance of the encrypter which uses keys of length 24 aa mandated by DESedeKeySpec.

Method Detail

crypt

protected byte[] crypt(String key,
                       byte[] value,
                       int mode)
                throws InvalidKeyException,
                       BadPaddingException,
                       RuntimeException
Encrypt/decrypt the specified value using the specified key.

Specified by:
crypt in class Encrypt
Parameters:
key - The key to use to encrypt the value.
value - The value that is to be encrypted or decrypted.
mode - The operation mode of this cipher (this is one of the following: Cipher.ENCRYPT_MODE, Cipher.DECRYPT_MODE, Cipher.WRAP_MODE or Cipher.UNWRAP_MODE).
Returns:
The encrypted bytes.
Throws:
InvalidKeyException - If the given key is inappropriate for initializing the Cipher, or its keysize exceeds the maximum allowable keysize (as determined from the configured jurisdiction policy files).
BadPaddingException - Thrown if the key cannot be used to decrypt the value. Should be thrown only during decrypt operations.
RuntimeException - If IllegalBlockSizeException, NoSuchPaddingException, NoSuchAlgorithmException are raised while encrypting or decrypting.
See Also:
Encrypt.getKey(java.lang.String)

SPT Core API