com.plumtree.openfoundation.security
Class XPRSACrypto

java.lang.Object
  extended bycom.plumtree.openfoundation.security.XPRSACrypto
All Implemented Interfaces:
IXPPKICrypto

public class XPRSACrypto
extends java.lang.Object
implements IXPPKICrypto

Encrypts and decrypts using public key encryption with the RSA algorithm.


Constructor Summary
XPRSACrypto()
           
 
Method Summary
 java.lang.String Decrypt(java.lang.String value, IXPPKIPrivateKey key)
          Decrypts the given string using RSA private-key decryption.
 java.lang.String Encrypt(java.lang.String value, IXPPKIPublicKey key)
          Encrypts the given string with the given key using RSA public-key encryption.
 IXPPKIKeyPair GenerateKeys(int strength, XPSecureRandom rand)
          Call this method to generate an RSA public-key/private-key pair.
 java.lang.String Sign(java.lang.String value, IXPPKIPrivateKey key)
          Signs the data in the given string with the RSA private-key.
 java.lang.String VerifySignature(java.lang.String value, IXPPKIPublicKey key)
          Verifies the signed text with the RSA public-key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XPRSACrypto

public XPRSACrypto()
Method Detail

Encrypt

public java.lang.String Encrypt(java.lang.String value,
                                IXPPKIPublicKey key)
Encrypts the given string with the given key using RSA public-key encryption. Translates the string passed in into a byte array using UTF-8 encoding. Creates an XPBigInteger from these bytes, and performs the RSA algorithm. The resulting XPBigInteger is translated back into a byte array that is then Base64 encoded into a string and returned.

Specified by:
Encrypt in interface IXPPKICrypto
Parameters:
value - string to be encrypted
key - RSA public key holding an exponent and modulus
Returns:
a string containing the encoded bytes
Throws:
XPIllegalArgumentException - if the input string is too large to encrypt with the current bit strength

Decrypt

public java.lang.String Decrypt(java.lang.String value,
                                IXPPKIPrivateKey key)
Decrypts the given string using RSA private-key decryption. Translates the string passed in into a byte array using Base64 decoding. The bytes are then translated into an XPBigInteger and the RSA algorithm is performed. The resulting XPBigInteger is translated into bytes, which are then translated into a string using UTF-8 encoding.

Specified by:
Decrypt in interface IXPPKICrypto
Parameters:
value - the string to decrypt
key - RSA private key holding an exponent and modulus
Returns:
the decrypted string message

Sign

public java.lang.String Sign(java.lang.String value,
                             IXPPKIPrivateKey key)
Signs the data in the given string with the RSA private-key.

Specified by:
Sign in interface IXPPKICrypto
Parameters:
value - data to be signed
key - RSA private key holding an exponent and modulus
Returns:
encrypted/signed string
Throws:
XPIllegalArgumentException - if the input string is too large to sign with the current bit strength

VerifySignature

public java.lang.String VerifySignature(java.lang.String value,
                                        IXPPKIPublicKey key)
Verifies the signed text with the RSA public-key.

Specified by:
VerifySignature in interface IXPPKICrypto
Parameters:
value - signed string
key - RSA public key holding an exponent and modulus
Returns:
String value of Encoding.

GenerateKeys

public IXPPKIKeyPair GenerateKeys(int strength,
                                  XPSecureRandom rand)
Call this method to generate an RSA public-key/private-key pair. The strength determines the number the bits in the random large primes used to generate the public and private key values. The recommended value to use is 1024. 512 bits is not considered secure enough, and 2048 will greatly increase the running time.

Specified by:
GenerateKeys in interface IXPPKICrypto
Parameters:
strength - number of bits to use
rand - source of randomness
Returns:
key pair object holding the public and private keys


Copyright 2002, 2003, 2004 Plumtree Software Inc. All Rights Reserved.