java.lang.Object
com.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();
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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
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
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