Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.traxel.crypto
Class CipherPartner  view CipherPartner download CipherPartner.java

java.lang.Object
  extended bycom.traxel.crypto.CipherPartner

public class CipherPartner
extends java.lang.Object

NOTE: TEST_PARAMS are not intended for production use.

Test Usage

   // DHParameterSpecs can be safely published to all parties.
   alice = new CipherPartner( "ALICE", CipherPartner.TEST_PARAMS );
   bob = new CipherPartner( "BOB", CipherPartner.TEST_PARAMS );
   
   alicePublicEncoded = alice.getPublicEncoded();
   
   // transmit alicePublicEncoded to bob
   // Alternately, alice could load from disk and bob could
   // already have a copy of alice's public key.
   
   // bob initializes only from alices key, and generates IV
   bob.initFromPartner( alicePublicEncoded );
   bobPublicEncoded = bob.getPublicEncoded();
   bobIv = bob.getIv();

   // transmit bobPublicEncoded and bobIV to alice

   // alice requires bobPublicEncoded and bobIv
   alice.initFromPartner( bobPublicEncoded, bobIv );
   aliceEncrypt = alice.getEncryptCipher();
   aliceDecrypt = alice.getDecryptCipher();
   
   bobEncrypt = alice.getEncrypt();
   bobDecrypt = alice.getDecrypt();
 


Field Summary
private  javax.crypto.SecretKey _blowfishKey
           
private  javax.crypto.Cipher _decryptCipher
           
private  javax.crypto.KeyAgreement _dhKeyAgree
           
private  java.security.KeyPair _dhKeyPair
           
private  javax.crypto.Cipher _encryptCipher
           
private  byte[] _iv
           
private  java.lang.String _name
           
static java.lang.String DEFAULT_PROVIDER_NAME
           
static java.lang.String DIGEST_ALGORITHM
           
static java.lang.String PRIVATE_ALGORITHM
           
static java.lang.String PRIVATE_TRANSFORM
           
static java.lang.String PUBLIC_ALGORITHM
           
static java.lang.String SHA1
           
static java.math.BigInteger TEST_G
           
static java.math.BigInteger TEST_P
           
static javax.crypto.spec.DHParameterSpec TEST_PARAMS
           
 
Constructor Summary
CipherPartner(java.lang.String name, CipherPartner copyFrom)
          This is typically called by a parent process that is spawning a number of child processes, all of which share a common Diffie Hellman key set.
CipherPartner(java.lang.String name, javax.crypto.spec.DHParameterSpec dhParams)
          This is the first partner initialized.
CipherPartner(java.lang.String name, javax.crypto.interfaces.DHPublicKey pubKey, javax.crypto.interfaces.DHPrivateKey privKey)
           
CipherPartner(java.lang.String name, java.lang.String pubKeyFile, java.lang.String privKeyFile)
           
 
Method Summary
protected  void dhKeyAndAgree(javax.crypto.spec.DHParameterSpec dhSpec)
           
 void exportDhKeys(java.lang.String pubKeyFile, java.lang.String privKeyFile, java.lang.String pubSha1File)
           
protected  javax.crypto.SecretKey getBlowfishKey()
           
 javax.crypto.Cipher getDecryptCipher()
           
protected  javax.crypto.KeyAgreement getDhKeyAgree()
           
protected  java.security.KeyPair getDhKeyPair()
           
 javax.crypto.Cipher getEncryptCipher()
           
 byte[] getIv()
           
 java.lang.String getName()
           
 java.lang.String getPrivateBase16()
           
 byte[] getPrivateEncoded()
           
 java.lang.String getPublicBase16()
           
 byte[] getPublicEncoded()
           
 java.lang.String getPublicSha1Base16()
           
 void initFromPartner(byte[] partnerPublicEncoded)
          This is used when an IV has not yet been generated.
 void initFromPartner(byte[] partnerPublicEncoded, byte[] partnerIv)
           
static void main(java.lang.String[] args)
           
protected  void setBlowfishKey(javax.crypto.SecretKey blowfishKey)
           
protected  void setDecryptCipher(javax.crypto.Cipher decryptCipher)
           
protected  void setDhKeyAgree(javax.crypto.KeyAgreement dhKeyAgree)
           
protected  void setDhKeyPair(java.security.KeyPair dhKeyPair)
           
protected  void setEncryptCipher(javax.crypto.Cipher encryptCipher)
           
protected  void setIv(byte[] iv)
           
protected  void setName(java.lang.String name)
           
static boolean verify(java.lang.String publicBase16, java.lang.String sha1Base16)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEST_G

public static final java.math.BigInteger TEST_G

TEST_P

public static final java.math.BigInteger TEST_P

TEST_PARAMS

public static final javax.crypto.spec.DHParameterSpec TEST_PARAMS

PUBLIC_ALGORITHM

public static final java.lang.String PUBLIC_ALGORITHM
See Also:
Constant Field Values

PRIVATE_ALGORITHM

public static final java.lang.String PRIVATE_ALGORITHM
See Also:
Constant Field Values

PRIVATE_TRANSFORM

public static final java.lang.String PRIVATE_TRANSFORM
See Also:
Constant Field Values

SHA1

public static final java.lang.String SHA1
See Also:
Constant Field Values

DIGEST_ALGORITHM

public static final java.lang.String DIGEST_ALGORITHM
See Also:
Constant Field Values

DEFAULT_PROVIDER_NAME

public static final java.lang.String DEFAULT_PROVIDER_NAME
See Also:
Constant Field Values

_name

private java.lang.String _name

_dhKeyPair

private java.security.KeyPair _dhKeyPair

_dhKeyAgree

private javax.crypto.KeyAgreement _dhKeyAgree

_blowfishKey

private javax.crypto.SecretKey _blowfishKey

_encryptCipher

private javax.crypto.Cipher _encryptCipher

_decryptCipher

private javax.crypto.Cipher _decryptCipher

_iv

private byte[] _iv
Constructor Detail

CipherPartner

public CipherPartner(java.lang.String name,
                     CipherPartner copyFrom)
This is typically called by a parent process that is spawning a number of child processes, all of which share a common Diffie Hellman key set.


CipherPartner

public CipherPartner(java.lang.String name,
                     javax.crypto.spec.DHParameterSpec dhParams)
This is the first partner initialized. It does not require a partner public key because it is the first partner. The other partner *must* be instantiated with this partner's public key.


CipherPartner

public CipherPartner(java.lang.String name,
                     javax.crypto.interfaces.DHPublicKey pubKey,
                     javax.crypto.interfaces.DHPrivateKey privKey)

CipherPartner

public CipherPartner(java.lang.String name,
                     java.lang.String pubKeyFile,
                     java.lang.String privKeyFile)
              throws java.io.FileNotFoundException,
                     java.lang.SecurityException,
                     java.io.IOException,
                     java.security.InvalidKeyException,
                     java.security.spec.InvalidKeySpecException
Method Detail

initFromPartner

public void initFromPartner(byte[] partnerPublicEncoded)
                     throws java.security.InvalidKeyException,
                            java.security.spec.InvalidKeySpecException,
                            java.security.InvalidAlgorithmParameterException
This is used when an IV has not yet been generated. This is the first partner to receive the other partner's key.


initFromPartner

public void initFromPartner(byte[] partnerPublicEncoded,
                            byte[] partnerIv)
                     throws java.security.InvalidKeyException,
                            java.security.InvalidAlgorithmParameterException,
                            java.security.spec.InvalidKeySpecException

getPublicBase16

public java.lang.String getPublicBase16()

getPrivateBase16

public java.lang.String getPrivateBase16()

getPublicSha1Base16

public java.lang.String getPublicSha1Base16()

verify

public static boolean verify(java.lang.String publicBase16,
                             java.lang.String sha1Base16)

exportDhKeys

public void exportDhKeys(java.lang.String pubKeyFile,
                         java.lang.String privKeyFile,
                         java.lang.String pubSha1File)
                  throws java.io.FileNotFoundException,
                         java.io.IOException,
                         java.lang.Exception

dhKeyAndAgree

protected void dhKeyAndAgree(javax.crypto.spec.DHParameterSpec dhSpec)
                      throws java.security.InvalidAlgorithmParameterException

setName

protected void setName(java.lang.String name)

setDhKeyPair

protected void setDhKeyPair(java.security.KeyPair dhKeyPair)

setDhKeyAgree

protected void setDhKeyAgree(javax.crypto.KeyAgreement dhKeyAgree)

setBlowfishKey

protected void setBlowfishKey(javax.crypto.SecretKey blowfishKey)

setEncryptCipher

protected void setEncryptCipher(javax.crypto.Cipher encryptCipher)

setDecryptCipher

protected void setDecryptCipher(javax.crypto.Cipher decryptCipher)

setIv

protected void setIv(byte[] iv)

getDhKeyPair

protected java.security.KeyPair getDhKeyPair()

getDhKeyAgree

protected javax.crypto.KeyAgreement getDhKeyAgree()

getBlowfishKey

protected javax.crypto.SecretKey getBlowfishKey()

getName

public java.lang.String getName()

getEncryptCipher

public javax.crypto.Cipher getEncryptCipher()

getDecryptCipher

public javax.crypto.Cipher getDecryptCipher()

getIv

public byte[] getIv()

getPublicEncoded

public byte[] getPublicEncoded()

getPrivateEncoded

public byte[] getPrivateEncoded()

main

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