JSecurity

org.jsecurity.crypto
Interface Cipher

All Known Implementing Classes:
BlowfishCipher

public interface Cipher

A Cipher is an algorithm used in cryptography that converts an original input source using a Key to an uninterpretable format. The resulting encrypted output is only able to be converted back to original form with a Key as well.

In what is known as Symmetric Ciphers, the Key used to encrypt the source is the same as (or trivially similar to) the Key used to decrypt it.

In Assymetric Ciphers, the encryption Key is not the same as the decryption Key. The most common type of Assymetric Ciphers are based on what is called public/private key pairs:

A private key is known only to a single party, and as its name implies, is supposed be kept very private and secure. A public key that is associated with the private key can be disseminated freely to anyone. Then data encrypted by the public key can only be decrypted by the private key and vice versa, but neither party need share their private key with anyone else. By not sharing a private key, you can guarantee no 3rd party can intercept the key and therefore use it to decrypt a message.

This assymetric key technology was created as a more secure alternative to symmetric ciphers that sometimes suffer from man-in-the-middle attacks since, for data shared between two parties, the same Key must also be shared and may be compromised.

Note that a symmetric cipher is perfectly fine to use if you just want to encode data in a format no one else can understand and you never give away the key. JSecurity uses a symmetric cipher when using certain HTTP Cookies for example - because it is often undesireable to have user's identity stored in a plain-text cookie, that identity can be converted via a symmetric cipher. Since the the same exact JSecurity application will receive the cookie, it can decrypt it via the same Key and there is no potential for discovery since that Key is never shared with anyone.

Since:
0.9
Author:
Les Hazlewood
See Also:
BlowfishCipher

Method Summary
 byte[] decrypt(byte[] encrypted, byte[] decryptionKey)
          Decrypts encrypted data via the specified Cipher key and returns the original (pre-encrypted) data.
 byte[] encrypt(byte[] raw, byte[] encryptionKey)
          Encrypts data via the specified Cipher key.
 

Method Detail

encrypt

byte[] encrypt(byte[] raw,
               byte[] encryptionKey)
Encrypts data via the specified Cipher key. Note that the key must be in a format understood by the Cipher implementation.

Parameters:
raw - the data to encrypt
encryptionKey - the Cipher key used during encryption.
Returns:
an encrypted representation of the specified raw data.

decrypt

byte[] decrypt(byte[] encrypted,
               byte[] decryptionKey)
Decrypts encrypted data via the specified Cipher key and returns the original (pre-encrypted) data. Note that the key must be in a format understood by the Cipher implementation.

Parameters:
encrypted - the previously encrypted data to decrypt
decryptionKey - the Cipher key used during decryption.
Returns:
the original form of the specified encrypted data.

JSecurity

Copyright © 2004-2008 JSecurity.