org.keyczar
Class Crypter

java.lang.Object
  extended by org.keyczar.Encrypter
      extended by org.keyczar.Crypter

public class Crypter
extends Encrypter

Crypters may both encrypt and decrypt data using sets of symmetric or private keys. Sets of public keys may only be used with Encrypter objects.

Author:
steveweis@gmail.com (Steve Weis)

Constructor Summary
Crypter(KeyczarReader reader)
          Initialize a new Crypter with a KeyczarReader.
Crypter(java.lang.String fileLocation)
          Initialize a new Crypter with a key set location.
 
Method Summary
 byte[] decrypt(byte[] input)
          Decrypt the given byte array of ciphertext
 void decrypt(java.nio.ByteBuffer input, java.nio.ByteBuffer output)
          Decrypt the given ciphertext input ByteBuffer and write the decrypted plaintext to the output ByteBuffer
 java.lang.String decrypt(java.lang.String ciphertext)
          Decrypt the given web-safe Base64 encoded ciphertext and return the decrypted plaintext as a String.
 java.lang.String toString()
           
 
Methods inherited from class org.keyczar.Encrypter
ciphertextSize, encrypt, encrypt, encrypt
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Crypter

public Crypter(KeyczarReader reader)
        throws KeyczarException
Initialize a new Crypter with a KeyczarReader. The corresponding key set must have a purpose 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.

Crypter

public Crypter(java.lang.String fileLocation)
        throws KeyczarException
Initialize a new Crypter with a key set location. This will attempt to read the keys using a KeyczarFileReader. The corresponding key set must have a purpose of 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

decrypt

public byte[] decrypt(byte[] input)
               throws KeyczarException
Decrypt the given byte array of ciphertext

Parameters:
input - The input ciphertext
Returns:
The decrypted plaintext
Throws:
KeyczarException - If the input is malformed, the ciphertext signature does not verify, the decryption key is not found, or a JCE error occurs.

decrypt

public void decrypt(java.nio.ByteBuffer input,
                    java.nio.ByteBuffer output)
             throws KeyczarException
Decrypt the given ciphertext input ByteBuffer and write the decrypted plaintext to the output ByteBuffer

Parameters:
input - The input ciphertext. Will not be modified.
output - The output buffer to write the decrypted plaintext
Throws:
KeyczarException - If the input is malformed, the ciphertext signature does not verify, the decryption key is not found, or a JCE error occurs.

decrypt

public java.lang.String decrypt(java.lang.String ciphertext)
                         throws KeyczarException
Decrypt the given web-safe Base64 encoded ciphertext and return the decrypted plaintext as a String.

Parameters:
ciphertext - The encrypted ciphertext in web-safe Base64 format
Returns:
The decrypted plaintext as a string
Throws:
KeyczarException - If the input is malformed, the ciphertext signature does not verify, the decryption key is not found, the input is not web-safe Base64 encoded, or a JCE error occurs.

toString

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