ch.elca.el4j.services.security.encryption
Class RSACipher

java.lang.Object
  extended by ch.elca.el4j.services.security.encryption.RSACipher
All Implemented Interfaces:
Serializable

public class RSACipher
extends Object
implements Serializable

Lightweight support for basic asymmetric encryption (RSA algorithm).

Adapted from RSA.java, an RSA Encryption Implementation. Copyright (C) 2003 Eugene Luzgin, eugene@luzgin.com

Author:
Fabian Reichlin (FRE), Laurent Bovet (LBO)
See Also:
Serialized Form
File-location:
RSACipher
Last check-in date:
2009-08-04 15:35:01 +0200 (Di, 04. Aug 2009) by swismer for revision 3883

Constructor Summary
RSACipher(int keyLength)
          Creates a new cipher for encryption and decryption.
RSACipher(String publicKey)
          Creates a new cipher for encryption and decryption.
 
Method Summary
 String decrypt(String encryptedMessage)
          Decripts a given message, by using the private key of this cipher.
 String encrypt(String text)
          Encrypts a given text, by using the public key of the cipher.
 String getPublicKey()
          Returns the public key of this cipher.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RSACipher

public RSACipher(int keyLength)
Creates a new cipher for encryption and decryption. It generates a new key pair.

Parameters:
keyLength - The length of the key. That the algorithm does not work with all values, typical key lengths are 512, 1024, 2048, 3072 and 4096. Note that longer keys are more secure but also slower (several minutes). Keys of length < 1024 are considered unsecure, 1024 is the minimum but still not perfectly secure.

RSACipher

public RSACipher(String publicKey)
Creates a new cipher for encryption and decryption.

Parameters:
publicKey - The public key of the key pair.
Method Detail

getPublicKey

public String getPublicKey()
Returns the public key of this cipher.

Returns:
The public key of this cipher.

encrypt

public String encrypt(String text)
Encrypts a given text, by using the public key of the cipher.

Parameters:
text - The string to encrypt.
Returns:
An encrypted string.

decrypt

public String decrypt(String encryptedMessage)
Decripts a given message, by using the private key of this cipher.

Parameters:
encryptedMessage - The message to decrypt.
Returns:
The decrypted message.


Copyright © 2005-2011 ELCA. All Rights Reserved.