org.keyczar
Class Encrypter

java.lang.Object
  extended by org.keyczar.Encrypter
Direct Known Subclasses:
Crypter

public class Encrypter
extends java.lang.Object

Encrypters are used strictly to encrypt data. Typically, Encrypters will read sets of public keys, although may also be instantiated with sets of symmetric keys. Crypter objects should be used with symmetric or private key sets to decrypt data.

Author:
steveweis@gmail.com (Steve Weis)

Constructor Summary
Encrypter(KeyczarReader reader)
          Initialize a new Encrypter with a KeyczarReader.
Encrypter(java.lang.String fileLocation)
          Initialize a new Encrypter with a key set location.
 
Method Summary
 int ciphertextSize(int inputLength)
          Returns the size of the ciphertext output that would result from encrypting an input of the given length.
 byte[] encrypt(byte[] input)
          Encrypt the given input byte array.
 void encrypt(java.nio.ByteBuffer input, java.nio.ByteBuffer output)
          Encrypt the given input ByteBuffer.
 java.lang.String encrypt(java.lang.String input)
          Encrypt a String and return a web-safe Base64 encoded ciphertext.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Encrypter

public Encrypter(KeyczarReader reader)
          throws KeyczarException
Initialize a new Encrypter with a KeyczarReader. The corresponding key set must have a purpose of either KeyPurpose.ENCRYPT or KeyPurpose.DECRYPT_AND_ENCRYPT.

Parameters:
reader - A reader to read keys from
Throws:
KeyczarException - In the event of an IO error reading keys or if the key set does not have the appropriate purpose.

Encrypter

public Encrypter(java.lang.String fileLocation)
          throws KeyczarException
Initialize a new Encrypter with a key set location. This will attempt to read the keys using a KeyczarFileReader. The corresponding key set must have a purpose of either KeyPurpose.ENCRYPT or KeyPurpose.DECRYPT_AND_ENCRYPT

Parameters:
fileLocation - Directory containing a key set
Throws:
KeyczarException - In the event of an IO error reading keys or if the key set does not have the appropriate purpose.
Method Detail

ciphertextSize

public int ciphertextSize(int inputLength)
                   throws KeyczarException
Returns the size of the ciphertext output that would result from encrypting an input of the given length.

Parameters:
inputLength - The length of the input.
Returns:
Length of the ciphertext that would be produced.
Throws:
KeyczarException - If the key set contains no primary encrypting key.

encrypt

public byte[] encrypt(byte[] input)
               throws KeyczarException
Encrypt the given input byte array.

Parameters:
input - The input to encrypt
Returns:
The encrypted ciphertext
Throws:
KeyczarException - If there is a JCE exception or the key set does not contain a primary encrypting key.

encrypt

public void encrypt(java.nio.ByteBuffer input,
                    java.nio.ByteBuffer output)
             throws KeyczarException
Encrypt the given input ByteBuffer.

Parameters:
input - The input buffer to encrypt. Will not be modified
output - The buffer to write the output ciphertext to.
Throws:
KeyczarException - If there is a JCE exception, the key set does not contain a primary encrypting key, or the output buffer is too small.

encrypt

public java.lang.String encrypt(java.lang.String input)
                         throws KeyczarException
Encrypt a String and return a web-safe Base64 encoded ciphertext.

Parameters:
input - An String to encrypt.
Returns:
A web-safe Base64 encoded ciphertext.
Throws:
KeyczarException - If there is a JCE exception or the key set does not contain a primary encrypting key.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object