org.webdocwf.util.smime.crypto
Class SymmetricEncryption

java.lang.Object
  |
  +--org.webdocwf.util.smime.crypto.SymmetricEncryption

public class SymmetricEncryption
extends java.lang.Object

SymmetricEncryption class is used for symmetric encryption large amounts of data. Algorithm names and corresponding key lengths are:
DES - 56
DES_EDE3_CBC - 128, 192
RC2_CBC - 40, 64, 128


Constructor Summary
SymmetricEncryption(java.lang.String algorithmName0, int keyLength0)
          Construction with the given algorithm name and key size in bits.
 
Method Summary
 void decryption(byte[] forDecrypt)
          Decription of the byte array with the symmetric key and IV previously generated by the process of encryption in the same session with the same object.
 void decryption(byte[] forDecrypt, byte[] simKey0, byte[] iv0)
          Decription of the byte array with the given symmetric key and initialization vector (IV)
 void encryption(byte[] forEncrypt0)
          Encryption of the byte array with random generated key
 void encryption(byte[] forEncrypt0, byte[] simKey0)
          Encryption of the byte array with the given symmetric key
 java.lang.String getAlgorithmName()
          Returns the algorithm name used for symmetric encryption.
 byte[] getDecryptedValue()
          Returns the decrypted content
 byte[] getEncryptedValue()
          Returns the encrypted content.
 byte[] getIV()
          Returns the initialization vector (IV) used for Symmetric Cipher and the chosen algorithm.
 int getKeyLength()
          Returns the key size in bits used for chosen algorithm name.
 byte[] getSymmetricKey()
          Returns the generated symmetric key in bytes.
 void reset()
          Resets (sets to null) all private attributes in generated instance of the class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SymmetricEncryption

public SymmetricEncryption(java.lang.String algorithmName0,
                           int keyLength0)
                    throws SMIMEException
Construction with the given algorithm name and key size in bits.
Parameters:
algorithmName0 - is name of algorithm: "DES", "DES_EDE3_CBC" or "RC2_CBC".
keyLength - is key size in bits.
Throws:
SMIMEException - thrown in case of invalid algorithm names, or in case of wrong key sizes in bits.
Method Detail

encryption

public void encryption(byte[] forEncrypt0)
                throws SMIMEException
Encryption of the byte array with random generated key
Parameters:
forEncrypt0 - is byte array for encryption
Throws:
SMIMEException - caused by non SMIMEException which can be one of the following: NoSuchPaddingException, NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException.

encryption

public void encryption(byte[] forEncrypt0,
                       byte[] simKey0)
                throws SMIMEException
Encryption of the byte array with the given symmetric key
Parameters:
forEncrypt0 - is byte array for encryption
simKey0 - symmetric key
Throws:
SMIMEException - if number of bytes in imported symmetric Key is incorect. Also, can be caused by non SMIMEException which can be one of the following: NoSuchPaddingException, NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException.

getAlgorithmName

public java.lang.String getAlgorithmName()
Returns the algorithm name used for symmetric encryption.
Returns:
Name of the chosen algorithm for symmetric encryption.

getKeyLength

public int getKeyLength()
Returns the key size in bits used for chosen algorithm name.
Returns:
Key size in bits for the chosen algorithm for symmetric encryption.

getIV

public byte[] getIV()
Returns the initialization vector (IV) used for Symmetric Cipher and the chosen algorithm.
Returns:
IV as a byte array.

getSymmetricKey

public byte[] getSymmetricKey()
Returns the generated symmetric key in bytes.
Returns:
Symmetric key in byte array.

getEncryptedValue

public byte[] getEncryptedValue()
Returns the encrypted content.
Returns:
Encrypted content as byte array.

decryption

public void decryption(byte[] forDecrypt)
                throws SMIMEException
Decription of the byte array with the symmetric key and IV previously generated by the process of encryption in the same session with the same object. This method is mainly used in testing purposes.
Parameters:
forDecrypt - previosly encrypted byte array
Throws:
SMIMEException - caused by non SMIMEException which can be one of the following: NoSuchPaddingException, NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException.

decryption

public void decryption(byte[] forDecrypt,
                       byte[] simKey0,
                       byte[] iv0)
                throws SMIMEException
Decription of the byte array with the given symmetric key and initialization vector (IV)
Parameters:
forDecrypt - byte array for encryption
simKey0 - imported symetric key
iv0 - imported initialization vector
Throws:
SMIMEException - if number of bytes in imported symmetric key is incorect, or if number of bytes in imported IV isn't 8. Also, can be caused by non SMIMEException which can be one of the following: NoSuchPaddingException, NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException.

getDecryptedValue

public byte[] getDecryptedValue()
Returns the decrypted content
Returns:
Decrypted content as a byte array.

reset

public void reset()
Resets (sets to null) all private attributes in generated instance of the class.


Copyright © 2002-2002 Together Teamlösungen. All Rights Reserved.