org.xwiki.crypto.passwd
Interface PasswordCiphertext

All Superinterfaces:
Serializable

public interface PasswordCiphertext
extends Serializable

Ciphertext represents a single password encrypted data. It can be serialized and deserialized and the same password will be able to decrypt it.

Since:
2.5M1
Version:
$Id: 1c01c6ff1466eb91abff7f3c1d93f8f371ec9301 $

Method Summary
 byte[] decrypt(String password)
          Get the message (i.e.
 int getRequiredKeySize()
          Get the length of the key which should be output by the keyFunction which is to be passed to init(byte[], String, KeyDerivationFunction).
 void init(byte[] message, String password, KeyDerivationFunction initializedKeyFunction)
          Initialize this ciphertext with a given message (i.e.
 byte[] serialize()
          Serialize this ciphertext into a byte array which can later be deserialized and the text decrypted from that.
 

Method Detail

init

void init(byte[] message,
          String password,
          KeyDerivationFunction initializedKeyFunction)
          throws GeneralSecurityException
Initialize this ciphertext with a given message (i.e. plaintext), password, and an initialized key derivation function. To get the data back, use decrypt(String) with the same password.

Parameters:
message - the message which will be encrypted.
password - the password used to encrypt the message.
initializedKeyFunction - an initialized KeyDerivationFunction which will return a key of the length given by getRequiredKeySize().
Throws:
GeneralSecurityException - if something goes wrong while encrypting.

decrypt

byte[] decrypt(String password)
               throws GeneralSecurityException
Get the message (i.e. plaintext) back from this ciphertext. Most of the time the response is null if the password is incorrect, 1 out of 250 times the output is unintelligable garbage which sneaks undetected past the padding scheme.

Parameters:
password - the user supplied password.
Returns:
the original message or null if the password was wrong.
Throws:
GeneralSecurityException - if something goes wrong while decrypting.

serialize

byte[] serialize()
                 throws IOException
Serialize this ciphertext into a byte array which can later be deserialized and the text decrypted from that.

Returns:
a byte array representing this object.
Throws:
IOException - if something goes wrong in the serialization framework.

getRequiredKeySize

int getRequiredKeySize()
Get the length of the key which should be output by the keyFunction which is to be passed to init(byte[], String, KeyDerivationFunction). Users are expected to call this method and pass the result when initializing the key derivation function then pass the initialized key derivation function to init(byte[], String, KeyDerivationFunction).

Returns:
the length required for the derived key.
See Also:
getRequiredKeySize()


Copyright © 2004-2013 XWiki. All Rights Reserved.