org.clazzes.optional.sec.rsa
Class RSAPrivKey

java.lang.Object
  extended by org.clazzes.optional.sec.rsa.RSAPrivKey
Direct Known Subclasses:
RSACrtPrivKey

public class RSAPrivKey
extends java.lang.Object

An RSA private key with a passphrase-encrypted storage possibility. This class does not make use of the Chinese Remainder Theorem and hence stores the private exponent internally without the factorization of the modulus.


Constructor Summary
RSAPrivKey(BigInt modulus, BigInt pubExponent, BigInt privExponent)
          Construct an RSA private key from the given numbers.
 
Method Summary
static RSAPrivKey decode(java.io.InputStream is, byte[] passPhrase)
          Write the encrypted private key to an output stream.
protected static BigInt decodeBigInt(java.io.DataInputStream dis, boolean legacy)
          Decode an unsigned BigInt from a DataInputStream.
 BigInt decryptPlain(BigInt x)
          Calculates the plain decrpyt operation x^privExp.
 void encode(java.io.OutputStream os, byte[] passPhrase, RandomGenerator random)
          Write the encrypted private key to an output stream.
protected  void encodeEncryptedParts(java.io.DataOutputStream dos)
          Encode the encrypted parts.
 BigInt getModulus()
           
 BigInt getPubExponent()
           
 RSAPubKey getPubKey()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RSAPrivKey

public RSAPrivKey(BigInt modulus,
                  BigInt pubExponent,
                  BigInt privExponent)
Construct an RSA private key from the given numbers.

Parameters:
modulus - The modulus of operation.
pubExponent - The public exponent.
privExponent - The private exponent.
Method Detail

getModulus

public BigInt getModulus()
Returns:
The modulus of the RAS public key.

getPubExponent

public BigInt getPubExponent()
Returns:
The public exponent of the RSA key.

getPubKey

public RSAPubKey getPubKey()
Returns:
The associated public key.

decodeBigInt

protected static BigInt decodeBigInt(java.io.DataInputStream dis,
                                     boolean legacy)
                              throws java.io.IOException
Decode an unsigned BigInt from a DataInputStream.

Parameters:
dis - The DataInputStream to read from.
Returns:
The positive number decoded from the stream.
Throws:
java.io.IOException - Upon write errors.

encodeEncryptedParts

protected void encodeEncryptedParts(java.io.DataOutputStream dos)
                             throws java.io.IOException
Encode the encrypted parts. This function may be overwritten by more sophisticated implementations like implementations, which make use of the Chinese Remainder Theorem.

Parameters:
dos - The data output stream, which will be encrypted.
Throws:
java.io.IOException

encode

public void encode(java.io.OutputStream os,
                   byte[] passPhrase,
                   RandomGenerator random)
            throws java.io.IOException
Write the encrypted private key to an output stream.

Parameters:
os - The target output stream.
passPhrase - A pass phrase. If the pass phrase is a string it is highly recommended to use the UTF-8 representation of the pass phrase.
random - A random number generator used to generate salt bytes.
Throws:
java.io.IOException - Upon write errors.

decode

public static RSAPrivKey decode(java.io.InputStream is,
                                byte[] passPhrase)
                         throws java.io.IOException
Write the encrypted private key to an output stream.

Parameters:
os - The target output stream.
passPhrase - A pass phrase. If the pass phrase is a string it is highly recommended to use the UTF-8 representation of the pass phrase.
Throws:
java.io.IOException - Upon read errors.

decryptPlain

public BigInt decryptPlain(BigInt x)
Calculates the plain decrpyt operation x^privExp. This operation may additionally be used on a padded message digest to sign data.

Parameters:
x - The encrypted text.
Returns:
The decrypted plain text, which is usually subject to an appropriate padding scheme.


Copyright © 2010. All Rights Reserved.