au.net.aba.crypto.provider
Class RSA

java.lang.Object
  |
  +--javax.crypto.CipherSpi
        |
        +--au.net.aba.crypto.provider.BlockCipher
              |
              +--au.net.aba.crypto.provider.RSA

public class RSA
extends BlockCipher

A class that provides RSA public/private key encryption and decryption as specified in PKCS#1.

By default this cipher will use PKCS#1 padding however it also supports NoPadding.


Field Summary
static java.lang.String ident
           
 
Fields inherited from class au.net.aba.crypto.provider.BlockCipher
BLOCK_SIZE, buffer, bufferPos, CBC, cbcNextV, cbcV, ECB, firstBlock, ident, ivec, ivEncrypted, ivInline, key, mode, paddedStream, random, streamMode
 
Fields inherited from class javax.crypto.CipherSpi
ident
 
Constructor Summary
RSA()
           
 
Method Summary
protected  int decryptBlock(byte[] src, int srcIndex, int len, byte[] dst, int dstIndex)
          This method decrypts the specified array, placing the plain text data into the destination array.
protected  java.math.BigInteger encrypt(java.math.BigInteger plainText)
          Encrypt a data block.
protected  int encryptBlock(byte[] src, int srcIndex, int len, byte[] dst, int dstIndex)
          This method encrypts the specified array, placing the ciphered data into the destination array.
protected  int engineGetBlockSize()
          Returns the block size.
protected  int engineGetOutputSize(int inputLen)
          Returns the length in bytes that an output buffer would need to be in order to hold the result of the next update or doFinal operation, given the input length inputLen (in bytes).
 void engineSetMode(java.lang.String mode)
          Sets the mode of this cipher.
 void engineSetPadding(java.lang.String padding)
          Sets the padding mechanism of this cipher.
protected  void setKey(java.security.Key key)
          Re-key the cipher.
 
Methods inherited from class au.net.aba.crypto.provider.BlockCipher
engineDoFinal, engineDoFinal, engineGetIV, engineGetParameters, engineInit, engineInit, engineInit, engineUpdate, engineUpdate, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ident

public static final java.lang.String ident
Constructor Detail

RSA

public RSA()
Method Detail

setKey

protected void setKey(java.security.Key key)
               throws java.security.InvalidKeyException
Description copied from class: BlockCipher
Re-key the cipher. If the provided Key is not compatible with this cipher the exception should throw an InvalidKeyException.
Overrides:
setKey in class BlockCipher

engineSetMode

public void engineSetMode(java.lang.String mode)
                   throws java.security.NoSuchAlgorithmException
Sets the mode of this cipher.
Overrides:
engineSetMode in class BlockCipher
Parameters:
mode - the mode of the cipher (ECB, CBC). Currently only ECB is supported.
Throws:
java.security.NoSuchAlgorithmException - if the mode is not supported.

engineSetPadding

public void engineSetPadding(java.lang.String padding)
                      throws NoSuchPaddingException
Sets the padding mechanism of this cipher.
Overrides:
engineSetPadding in class BlockCipher
Parameters:
padding - the name of the type of padding to be applied, currently "PKCS1Padding", and "NoPadding" will be accepted.
Throws:
NoSuchPaddingException - if the padding type is unknown.

engineGetBlockSize

protected int engineGetBlockSize()
Returns the block size. In encryption mode this will be the size of the key less the header bytes, in decryption mode it will be the size of the key.
Overrides:
engineGetBlockSize in class BlockCipher
Tags copied from class: BlockCipher
Returns:
the block size (in bytes), or 0 if the underlying algorithm is not a block cipher

engineGetOutputSize

protected int engineGetOutputSize(int inputLen)
Returns the length in bytes that an output buffer would need to be in order to hold the result of the next update or doFinal operation, given the input length inputLen (in bytes).
Overrides:
engineGetOutputSize in class BlockCipher
Tags copied from class: BlockCipher
Parameters:
inputLen - the input length (in bytes)
Returns:
the required output buffer size (in bytes)

encryptBlock

protected final int encryptBlock(byte[] src,
                                 int srcIndex,
                                 int len,
                                 byte[] dst,
                                 int dstIndex)
                          throws IllegalBlockSizeException
This method encrypts the specified array, placing the ciphered data into the destination array.
Overrides:
encryptBlock in class BlockCipher
Parameters:
src - The plain text.
srcIndex - The index from which to read.
len - The length of the plain text.
dst - The cipher text.
dstIndex - The index at which to write.
Returns:
The number of bytes processed.

decryptBlock

protected final int decryptBlock(byte[] src,
                                 int srcIndex,
                                 int len,
                                 byte[] dst,
                                 int dstIndex)
                          throws BadPaddingException
This method decrypts the specified array, placing the plain text data into the destination array.
Overrides:
decryptBlock in class BlockCipher
Parameters:
src - The cipher text.
srcIndex - The index from which to read.
len - The lenght of the cipher text.
dst - The plain text.
dstIndex - The index at which to write.
Returns:
The number of bytes of plaintext.

encrypt

protected java.math.BigInteger encrypt(java.math.BigInteger plainText)
Encrypt a data block.
Parameters:
plainText - The plain text block to encrypt.
Returns:
The encrypted data.