com.sun.mfwk.security.crypto
Class MfCrypto

java.lang.Object
  extended bycom.sun.mfwk.security.crypto.MfCrypto

public class MfCrypto
extends java.lang.Object

This class is used to encrypt and decrypt blocs of data using the DES algorithm.

The key management can be managed by the class itself (by providing a file path which contains the key)
or can be handled by the caller (by providing the key as a SecretKey object or a byte[]).


Constructor Summary
MfCrypto()
          Creates a new instance of MfCrypto
MfCrypto(byte[] k)
          Creates a new instance of MfCrypto and initialises the secret key with the argument
MfCrypto(javax.crypto.SecretKey k)
          Creates a new instance of MfCrypto and initialises the secret key with the argument
 
Method Summary
 byte[] decrypt(byte[] buf)
          Takes a byte array as input and return a byte array which is decrypted using the symetric key
 byte[] encrypt(byte[] buf)
          Takes a byte array as input and return a byte array which is encrypted using the symetric key
 byte[] getKeyBytes()
          Get the key as a byte[]
 javax.crypto.SecretKey getKeyObject()
          Get the key as Key object
 void setKey(byte[] keybuf)
          sets the key with the argument
 void setKey(javax.crypto.SecretKey k)
          sets the key with the argument
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MfCrypto

public MfCrypto()
Creates a new instance of MfCrypto


MfCrypto

public MfCrypto(byte[] k)
         throws java.security.InvalidKeyException
Creates a new instance of MfCrypto and initialises the secret key with the argument

Parameters:
k - The key as a byte array.
Throws:
java.security.InvalidKeyException - if the key is null or invalid for DES algorithm

MfCrypto

public MfCrypto(javax.crypto.SecretKey k)
         throws java.security.InvalidKeyException
Creates a new instance of MfCrypto and initialises the secret key with the argument

Parameters:
k - The key as a SecretKey object.
Method Detail

setKey

public void setKey(javax.crypto.SecretKey k)
            throws java.security.InvalidKeyException
sets the key with the argument

Parameters:
k - The key as a SecretKey object.
Throws:
java.security.InvalidKeyException

setKey

public void setKey(byte[] keybuf)
            throws java.security.InvalidKeyException
sets the key with the argument

Parameters:
keybuf - the key as a byte array.
Throws:
java.security.InvalidKeyException - if the key is null or invalid for DES algorithm

getKeyObject

public javax.crypto.SecretKey getKeyObject()
Get the key as Key object

Returns:
a SecretKey object holding the Key

getKeyBytes

public byte[] getKeyBytes()
Get the key as a byte[]

Returns:
The key as a byte array

encrypt

public byte[] encrypt(byte[] buf)
               throws java.security.InvalidKeyException
Takes a byte array as input and return a byte array which is encrypted using the symetric key

Parameters:
buf - The buffer to encrypt.
Returns:
the encrypted byte array
Throws:
java.security.InvalidKeyException - if the key is null (not initialised) or invalid for DES algorithm

decrypt

public byte[] decrypt(byte[] buf)
               throws java.security.InvalidKeyException
Takes a byte array as input and return a byte array which is decrypted using the symetric key

Parameters:
buf - The buffer to decrypt.
Returns:
the decrypted byte array
Throws:
java.security.InvalidKeyException - if the key is null (not initialised) or invalid for DES algorithm