com.ibm.security.pkcs1
Class PKCS1

java.lang.Object
  |
  +--com.ibm.security.pkcs1.PKCS1

public final class PKCS1
extends Object

PKCS #1 object. This interface was derived from the RSA specifications at http://www.rsa.com/rsalabs/pubs/PKCS/. This class implements version 1.5 of the PKCS #1 specifications.

PKCS1 objects are immutable; they cannot be changed once created.


Field Summary
static String PKCS1_VERSION_1_5
          PKCS1 Version 1.5 = "1.5"
static String PKCS1_VERSION2
          PKCS1 Version 2.0 = "2.0"
 
Constructor Summary
PKCS1(String version, String encryptionAlg, String digestAlg, String mgf)
          Create a PKCS1 object with the input values.
PKCS1(String version, String encryptionAlg, String digestAlg, String mgf, String provider)
          Create a PKCS1 object with the input values.
 
Method Summary
 byte[] decrypt(PrivateKey privateKey, byte[] ciphertext)
          Decrypts the input ciphertext according to the encryption algorithm in this object.
 byte[] encrypt(Certificate cert, byte[] message)
          Encrypts the input message according to the encryption algorithm in this object.
 byte[] encrypt(PublicKey publicKey, byte[] message)
          Encrypts the input message according to the encryption algorithm in this object.
 String getEncryptionAlgorithmString()
          Returns the encryption algorithm string.
 String getMGF()
           
 String getSignatureAlgorithmString()
          Returns the signature algorithm string.
 String getSignatureHashAlgorithmString()
          Returns the signature digest algorithm string.
 String getVersion()
          Returns the version number.
 byte[] sign(PrivateKey privateKey, byte[] message)
          Creates a digital signature using the input message and the signature algorithmin this object.
 String toString()
          Returns a string representation of the PKCS1 object.
 boolean verify(Certificate cert, byte[] message, byte[] signature)
          Verifies the input digital signature against the input message.
 boolean verify(PublicKey publicKey, byte[] message, byte[] signature)
          Verifies the input digital signature against the input message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PKCS1_VERSION_1_5

public static final String PKCS1_VERSION_1_5
PKCS1 Version 1.5 = "1.5"

PKCS1_VERSION2

public static final String PKCS1_VERSION2
PKCS1 Version 2.0 = "2.0"
Constructor Detail

PKCS1

public PKCS1(String version,
             String encryptionAlg,
             String digestAlg,
             String mgf,
             String provider)
Create a PKCS1 object with the input values.
Parameters:
version - the version number. Currently ignored, as only PKCS1.PKCS1_VERSION_1_5 is supported.
encryptionAlg - is the encryption algorithm. Currently ignored, as only RSA is supported.
digestAlg - is the digest algorithm. Valid values are SHA, MD2 and MD5. The default value is SHA.
mgf - is the message generation function. Currently ignored, as no message generation functions are supported in this release.
Throws:
IllegalArgumentException - if an unsupported argument has been specified.

PKCS1

public PKCS1(String version,
             String encryptionAlg,
             String digestAlg,
             String mgf)
Create a PKCS1 object with the input values.
Parameters:
version - the version number. Currently ignored, as only PKCS1.PKCS1_VERSION_1_5 is supported.
encryptionAlg - is the encryption algorithm. Currently ignored, as only RSA is supported.
digestAlg - is the digest algorithm. Valid values are SHA, MD2 and MD5. The default value is SHA.
mgf - is the message generation function. Currently ignored, as no message generation functions are supported in this release.
provider - the provider to be used.
Throws:
IllegalArgumentException - if an unsupported argument has been specified.
Method Detail

getVersion

public String getVersion()
Returns the version number. The version number is an immutable object.
Returns:
a String representing the version: "1.5" or "2.0" for version 1.5 and version 2.0 respectively.

getEncryptionAlgorithmString

public String getEncryptionAlgorithmString()
Returns the encryption algorithm string. The encryption algorithm string is an immutable object.
Returns:
the encryption algorithm (RSA).

getSignatureHashAlgorithmString

public String getSignatureHashAlgorithmString()
Returns the signature digest algorithm string. The signature digest algorithm string is an immutable object.
Returns:
the signature digest algorithm (MD2, MD5, SHA).

getSignatureAlgorithmString

public String getSignatureAlgorithmString()
Returns the signature algorithm string. The signature algorithm string is an immutable object.
Returns:
the signature algorithm (MD2withRSA, MD5withRSA, SHA1withRSA).

getMGF

public String getMGF()

encrypt

public byte[] encrypt(PublicKey publicKey,
                      byte[] message)
               throws PKCSException,
                      NoSuchAlgorithmException
Encrypts the input message according to the encryption algorithm in this object.
Parameters:
publicKey - the RSA public key used to encrypt the message.
message - the message to be encrypted.
Returns:
the encrypted message.
Throws:
PKCSException - for encryption errors.
IllegalArgumentException - for argument errors.

encrypt

public byte[] encrypt(Certificate cert,
                      byte[] message)
               throws PKCSException,
                      NoSuchAlgorithmException
Encrypts the input message according to the encryption algorithm in this object.
Parameters:
cert - the certificate that contains the RSA public key used to encrypt the message.
message - the message to be encrypted.
Returns:
the encrypted message.
Throws:
PKCSException - for encryption errors.
IllegalArgumentException - for argument errors.

decrypt

public byte[] decrypt(PrivateKey privateKey,
                      byte[] ciphertext)
               throws PKCSException,
                      NoSuchAlgorithmException
Decrypts the input ciphertext according to the encryption algorithm in this object.
Parameters:
privateKey - the RSA private key used to decrypt the message.
ciphertext - the message to be decrypted.
Returns:
the decrypted message.
Throws:
PKCSException - for decryption errors.
IllegalArgumentException - for argument errors.

sign

public byte[] sign(PrivateKey privateKey,
                   byte[] message)
            throws PKCSException,
                   NoSuchAlgorithmException
Creates a digital signature using the input message and the signature algorithmin this object.
Parameters:
privateKey - the RSA private key used to create the signature.
message - the message to be signed.
Returns:
the digital signature.
Throws:
PKCSException - for signing errors.

verify

public boolean verify(PublicKey publicKey,
                      byte[] message,
                      byte[] signature)
               throws PKCSException,
                      NoSuchAlgorithmException
Verifies the input digital signature against the input message.
Parameters:
publicKey - the RSA public key used to verify the signature.
message - the message to be used in the verification process. This should be identical to the message used to create the input signature.
signature - the digital signature to be verified.
Returns:
true, if the signature is verified; false, otherwise.
Throws:
PKCSException - for signing errors.

verify

public boolean verify(Certificate cert,
                      byte[] message,
                      byte[] signature)
               throws PKCSException,
                      NoSuchAlgorithmException
Verifies the input digital signature against the input message.
Parameters:
cert - the certificate containing the RSA public key used to verify the signature.
message - the message to be used in the verification process. This should be identical to the message used to create the input signature.
signature - the digital signature to be verified.
Returns:
true, if the signature is verified; false, otherwise.
Throws:
PKCSException - for signing errors.

toString

public String toString()
Returns a string representation of the PKCS1 object.
Overrides:
toString in class Object