ewe.security
Class RSAKey

java.lang.Object
  extended byewe.security.RSAKey
All Implemented Interfaces:
ByteEncodable, EncryptionKey

public class RSAKey
extends Object
implements ByteEncodable, EncryptionKey

An RSAKey holds either a private or public key and will also perform encryption/decryption operations. No data as to whether it is private or public is stored here, you can place that in a higher level object if needed.

Note that due to the nature of this encryption calling decrypt() on data generated by encrypt() on the same key will not yield the original text. With this type of encryption you can only use a key to decrypt the data encrypted by its public/private counterpart.

Use the class RSA to generate a new pair of keys.


Field Summary
protected  BigInteger exp
           
protected  BigInteger value
           
 
Constructor Summary
protected RSAKey()
           
  RSAKey(byte[] encodedBytes, int offset, int length)
          This creates the key from the bytes as encoded by encodeBytes.
 
Method Summary
 byte[] decrypt(byte[] encrypted, int offset, int length)
          Decrypt the data as encrypted by this key's counterpart.
 int encodeBytes(ByteArray dest)
          Used to store the key in a stream of bytes.
 byte[] encrypt(byte[] data, int offset, int length)
          Encrypt the provided data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

exp

protected BigInteger exp

value

protected BigInteger value
Constructor Detail

RSAKey

protected RSAKey()

RSAKey

public RSAKey(byte[] encodedBytes,
              int offset,
              int length)
       throws StreamCorruptedException
This creates the key from the bytes as encoded by encodeBytes.

Method Detail

encodeBytes

public int encodeBytes(ByteArray dest)
Used to store the key in a stream of bytes. It is recommended that whenever the private key is stored it is encrypted using an encryption like that provided by ewe.security.Encryptor.

Specified by:
encodeBytes in interface ByteEncodable
Parameters:
dest - The destination ByteArray, or null to determine the number of bytes needed to encode.
Returns:
The number of bytes appended to the ByteArray or the number of bytes needed to encode.

encrypt

public byte[] encrypt(byte[] data,
                      int offset,
                      int length)
               throws IOException
Encrypt the provided data.

Specified by:
encrypt in interface EncryptionKey
Throws:
IOException

decrypt

public byte[] decrypt(byte[] encrypted,
                      int offset,
                      int length)
               throws IOException
Decrypt the data as encrypted by this key's counterpart.

Specified by:
decrypt in interface EncryptionKey
Throws:
IOException