crypto
Class SymmetricCipher

java.lang.Object
  extended by crypto.SymmetricCipher

public class SymmetricCipher
extends java.lang.Object

Instances of the Symmetric cipher class arew used to cipher peer-to-peer datagram packets. Cipher's secret key is exchanged using asymmetric cipher.

Author:
Mikica B Kocic

Field Summary
private  javax.crypto.Cipher cipher
          Instance of the cipher used to encrypt/decrypt data.
private static java.lang.String mode
          Cipher-Block Chaining mode.
private static java.lang.String padding
          PKCS5 padding.
private  javax.crypto.SecretKey secretKey
          Secret key used to encrypt/decrypt data.
private  java.lang.String verificator
          Contains name of the verificator (i.e the name associated with authorized public key that has verified this public key).
 
Constructor Summary
SymmetricCipher(javax.crypto.SecretKey secretKey, java.lang.String verificator)
          Wraps existing secret key with information about verificatory (if any).
SymmetricCipher(java.lang.String algorithm, int keySize, boolean attnReport)
          Generates a new secret key using specified algorithm and key size.
 
Method Summary
 byte[] decrypt(int randomPreambleLen, byte[] cipherText)
          Decrypts cipher text first then discards random preamble of the given length.
 java.lang.String decrypt(java.lang.String encodedCipherText)
          Decodes Base64 encoded cipher text, decrypts text message and discards random preamble.
 byte[] encrypt(int randomPreambleLen, byte[] plainText)
          Encrypts random preamble of the given length appended with the input plain text.
 java.lang.String encrypt(java.lang.String plainText)
          Encrypts text message with random preamble and returns Base64 encoded cipher text.
 java.lang.String getAlgorithmDesc()
          Returns description of the cipher algorithm
 javax.crypto.SecretKey getSecretKey()
          Returns secret key.
 java.lang.String getVerificatorName()
          Returns if name of the verificator from authorized keys that verified this public key
 boolean isActive()
          Returns if cipher is properly initialized
 boolean isVerified()
          Returns if public key was verified
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mode

private static final java.lang.String mode
Cipher-Block Chaining mode. \see http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation

See Also:
Constant Field Values

padding

private static final java.lang.String padding
PKCS5 padding. \see http://www.ietf.org/rfc/rfc2898.txt

See Also:
Constant Field Values

cipher

private javax.crypto.Cipher cipher
Instance of the cipher used to encrypt/decrypt data.


secretKey

private javax.crypto.SecretKey secretKey
Secret key used to encrypt/decrypt data.


verificator

private java.lang.String verificator
Contains name of the verificator (i.e the name associated with authorized public key that has verified this public key). Not null indicates that the public key was successfully verified.

Constructor Detail

SymmetricCipher

public SymmetricCipher(javax.crypto.SecretKey secretKey,
                       java.lang.String verificator)
Wraps existing secret key with information about verificatory (if any).


SymmetricCipher

public SymmetricCipher(java.lang.String algorithm,
                       int keySize,
                       boolean attnReport)
Generates a new secret key using specified algorithm and key size.

Method Detail

getSecretKey

public javax.crypto.SecretKey getSecretKey()
Returns secret key.


isActive

public boolean isActive()
Returns if cipher is properly initialized


isVerified

public boolean isVerified()
Returns if public key was verified


getVerificatorName

public java.lang.String getVerificatorName()
Returns if name of the verificator from authorized keys that verified this public key

Returns:
name of the verificator; May be null indicating not verified public key

getAlgorithmDesc

public java.lang.String getAlgorithmDesc()
Returns description of the cipher algorithm


encrypt

public byte[] encrypt(int randomPreambleLen,
                      byte[] plainText)
Encrypts random preamble of the given length appended with the input plain text.


decrypt

public byte[] decrypt(int randomPreambleLen,
                      byte[] cipherText)
Decrypts cipher text first then discards random preamble of the given length.


encrypt

public java.lang.String encrypt(java.lang.String plainText)
Encrypts text message with random preamble and returns Base64 encoded cipher text.


decrypt

public java.lang.String decrypt(java.lang.String encodedCipherText)
Decodes Base64 encoded cipher text, decrypts text message and discards random preamble.