org.silverpeas.util.crypto
Interface Cipher

All Known Implementing Classes:
AESCipher, BlockCipherWithPadding, BlowfishCipher, CAST5Cipher, CMSCipher

public interface Cipher

In cryptography, a cipher (or cypher) is an algorithm for encrypting or decrypting data. The encryption is the operation that converts information from plain text into code or cipher. The decryption is the operation that recovers information in plain text from a code or cipher. All implementation of a given cipher in Silverpeas must implement this interface.

When using a cipher the original information is known as plaintext, and the encrypted form as ciphertext. The ciphertext message contains all the information of the plaintext message, but is not in a format readable by a human or computer without the proper mechanism to decrypt it. The operation of a cipher usually depends on a piece of auxiliary information, called a key. A key must be selected before using a cipher to encrypt a message. Without knowledge of the key, it should be difficult, if not nearly impossible, to decrypt the resulting ciphertext into readable plaintext.

ciphers can be categorized in several ways:


Method Summary
 String decrypt(byte[] encryptedData, CipherKey keyCode)
          Decrypt the specified code or cipher by using the specified cryptographic key.
 byte[] encrypt(String data, CipherKey keyCode)
          Encrypts the specified data by using the specified cryptographic key.
 CipherKey generateCipherKey()
          Generates randomly a cipher key that can be used in the encryption and in the decryption of data with this cipher.
 CryptographicAlgorithmName getAlgorithmName()
          Gets the name of the algorithm of the cipher.
 

Method Detail

getAlgorithmName

CryptographicAlgorithmName getAlgorithmName()
Gets the name of the algorithm of the cipher.

Returns:
the algorithm name.

encrypt

byte[] encrypt(String data,
               CipherKey keyCode)
               throws CryptoException
Encrypts the specified data by using the specified cryptographic key. The String objects handled by the encryption is done according the UTF-8 charset.

Parameters:
data - the data to encode.
keyCode - the key to use in the encryption.
Returns:
the encrypted data in bytes.
Throws:
CryptoException - if an error has occurred in the data encryption.

decrypt

String decrypt(byte[] encryptedData,
               CipherKey keyCode)
               throws CryptoException
Decrypt the specified code or cipher by using the specified cryptographic key. The String objects handled by the encryption is done according the UTF-8 charset.

Parameters:
encryptedData - the data in bytes encrypted by this cipher.
keyCode - the key to use in the decryption.
Returns:
the decrypted data.
Throws:
CryptoException - if an error has occurred in the data decryption.

generateCipherKey

CipherKey generateCipherKey()
                            throws CryptoException
Generates randomly a cipher key that can be used in the encryption and in the decryption of data with this cipher.

Returns:
a computed key that can be used with this cipher in the encryption and in the decryption of data.
Throws:
CryptoException - if an error has occurred in the key generation.


Copyright © 2016 Silverpeas. All Rights Reserved.