MjSip Stack
v1.6

org.zoolu.tools
Class MD5OTP

java.lang.Object
  |
  +--org.zoolu.tools.MD5OTP

public class MD5OTP
extends java.lang.Object

OTP (One Time Pad) encryption algorithm based on MD5 hash function. It uses a PRG (Pseudo-Random-Generator) function in OFB (Output Feadback) to genarate a byte-stream (the OTP) that is XORed with the plaintext.
The PRG is based on MD5.

The OTP is calculated starting from a key and an IV, as follows:
h_0=hash(skey|iv)
h_i=hash(skey|h_i-1)

where:
hash(.)==MD5(.)
skey==key

while the ciphertext is calculated as follows:
c_0=iv
c_i=m_i XOR h_i with i=1,2,..

Note that optionally it could modified initializing the skey as follows:
skey==hash(key|iv)
in order to not keep in memory the secret key for long time


Constructor Summary
MD5OTP(byte[] skey)
          Creates a new MD5OTP with IV=0
MD5OTP(byte[] skey, byte[] iv)
          Creates a new MD5OTP
 
Method Summary
static byte[] decrypt(byte[] c, byte[] key)
          Decrypts an array of bytes with the IV at top.
static byte[] encrypt(byte[] m, byte[] key)
          Encrypts an array of bytes.
static void main(java.lang.String[] args)
           
 byte[] update(byte[] m)
          Encrypts a block of bytes
 void update(java.io.InputStream in, java.io.OutputStream out)
          Encrypts a byte stream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MD5OTP

public MD5OTP(byte[] skey,
              byte[] iv)
Creates a new MD5OTP

MD5OTP

public MD5OTP(byte[] skey)
Creates a new MD5OTP with IV=0
Method Detail

update

public byte[] update(byte[] m)
Encrypts a block of bytes

update

public void update(java.io.InputStream in,
                   java.io.OutputStream out)
Encrypts a byte stream

encrypt

public static byte[] encrypt(byte[] m,
                             byte[] key)
Encrypts an array of bytes. An IV is chosen and saved at top.

decrypt

public static byte[] decrypt(byte[] c,
                             byte[] key)
Decrypts an array of bytes with the IV at top.

main

public static void main(java.lang.String[] args)

MjSip Stack
v1.6