es.rediris.crypt
Class RSATool

java.lang.Object
  extended by es.rediris.crypt.RSATool

public class RSATool
extends Object

RSATool is a helper class for encrypting/decrypting messages using RSA algorithm in ECB mode. Also, it uses PKCS1 padding when makes its operations with messages.
Keys are in PEM (PKCS#8) format, so you need to include the Bouncy Castle Library.


Constructor Summary
RSATool()
          Generate an RSATool object, adding the Bouncy Castle Provider
 
Method Summary
 String decode(String data)
           
 String encode(String data)
          Encrypt a message using the private key
 Key getRsaPrivateKey()
          Get the private key, which has should been previously read
 PublicKey getRsaPublicKey()
          Get the public key, which has should been previously read
 void readRsaPrivateKeyPEM(String filename)
          Read a private key file in PEM PKCS 8 format.
 void readRsaPublicKeyPEM(String filename)
          Read a public key file in PEM PKCS 8 format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RSATool

public RSATool()
Generate an RSATool object, adding the Bouncy Castle Provider

Method Detail

getRsaPrivateKey

public Key getRsaPrivateKey()
Get the private key, which has should been previously read

Returns:
The private key, or null if it hasn't read before

readRsaPrivateKeyPEM

public void readRsaPrivateKeyPEM(String filename)
                          throws IOException
Read a private key file in PEM PKCS 8 format. The file should be like:
 -----BEGIN RSA PRIVATE KEY-----
 ...
 -----END RSA PRIVATE KEY-----
 

Parameters:
filename - The name of the file
Throws:
IOException

getRsaPublicKey

public PublicKey getRsaPublicKey()
Get the public key, which has should been previously read

Returns:
The public key, or null if it hasn't read before

readRsaPublicKeyPEM

public void readRsaPublicKeyPEM(String filename)
                         throws IOException
Read a public key file in PEM PKCS 8 format. The file should be like:
 -----BEGIN PUBLIC KEY-----
 ...
 -----END PUBLIC KEY-----
 

Parameters:
filename - The name of the file
Throws:
IOException

encode

public String encode(String data)
Encrypt a message using the private key

Parameters:
data - The message you want to encrypt
Returns:
The ciphered message in base 64

decode

public String decode(String data)