|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object
|
+--org.logi.crypto.Crypto
|
+--org.logi.crypto.keys.K
|
+--org.logi.crypto.keys.DHPrivateKey
This object holds one Diffie-Hellman key. They can be used for Diffie-Hellman key-exchange with the DHKeyExNoninter and related classes or directly for encryption and signatures, in which case it uses the ElGamal algorithm.
The modulus and generator for the group from which the key is chosen are fixed for a given key-size. They are pre-calculated for a few bit-sizes, but take long to claculate for others.
The CDS for a Diffie-Hellman key is DHKey(x,g,m,pub)
for a public key or DHKey(x,g,m,pri) for a private
key. In both cases x,g and m are
hexadecimal numbers.
DHKeyExNoninter, Serialized Form| Fields inherited from class org.logi.crypto.Crypto |
BIT, cdsPath, EMPTY_ARRAY, FOUR, keySource, NIBBLE, ONE, primeCertainty, random, TWO, ZERO |
| Fields inherited from interface java.security.Key |
serialVersionUID |
| Constructor Summary | |
DHPrivateKey(java.math.BigInteger x,
java.math.BigInteger g,
java.math.BigInteger m)
Create a new Diffie-Hellman private-key object. |
|
| Method Summary | |
int |
cipherBlockSize()
Returns the size of the blocks that can be decrypted in one call to decrypt(). |
static KeyPair |
createKeys(int n)
Create a pair of public/private keys in a group with an n bit modulo. |
static KeyPair |
createKeys(java.lang.String username,
java.lang.String password,
java.lang.String hashFunction,
int n)
Create a pair of public/private keys in a group with an n bit modulo. |
void |
decrypt(byte[] source,
int i,
byte[] dest,
int j)
Decrypt one block of data. |
boolean |
equals(java.lang.Object o)
Return true iff the two keys are equivalent. |
java.lang.String |
getAlgorithm()
The name of the algorithm is "Diffie-Hellman". |
byte[] |
getEncoded()
Return encoded version. |
Fingerprint |
getFingerprint()
Return the key's fingerprint using the default hash function. |
Fingerprint |
getFingerprint(java.lang.String algorithm)
Return the key's fingerprint using the specified hash function. |
java.lang.String |
getFormat()
Returns the name of the key-encoding format. |
java.math.BigInteger |
getG()
Return the generator for this key. |
static java.math.BigInteger |
getGenerator(java.math.BigInteger m)
Return a Generator for a modulus group. |
java.math.BigInteger |
getKey()
Return the BigInteger representing this key. |
java.math.BigInteger |
getM()
Return the modulus for this key. |
static java.math.BigInteger |
getModulus(int n)
Return a Diffie-Hellman modulus. |
DHPublicKey |
getPublic()
Return the public key from the pair. |
int |
getSize()
Return the "size" of the key. |
int |
hashCode()
Return a hash-code based on the keys SHA1 fingerprint. |
boolean |
isPrivate()
Returns true iff this is a private key. |
boolean |
matches(Key key)
Check if a key mathces this. |
Fingerprint |
matchFingerprint()
Returns the default fingerprint of the matching key in the key-pair. |
Fingerprint |
matchFingerprint(java.lang.String algorithm)
Returns the default fingerprint of the matching key in the key-pair. |
static DHPrivateKey |
parseCDS(java.lang.String[] param)
Used by Crypto.fromString when parsing a CDS. |
int |
plainBlockSize()
Returns the size of the blocks that can be encrypted in one call to encrypt(). |
void |
prettyPrint(java.io.PrintWriter out,
int ind,
int rec)
Print this object to out, indented with ind tabs, going down at most rec levels of recursion. |
Signature |
sign(Fingerprint fp)
Create a signature for a Fingerprint fith a private key. |
int |
signatureSize()
Returns the length of a signature in bytes. |
int |
signBlockSize()
Returns the maximum size in bytes of the fingerprints that can be signed. |
java.lang.String |
toString()
Return a CDS for this key. |
| Methods inherited from class org.logi.crypto.Crypto |
binString, binString, ensureArrayLength, ensureArrayLength, equal, equalRelaxed, equalSub, fromHexNibble, fromHexString, fromString, fromString, hexString, hexString, hexString, hexString, hexString, initRandom, initRandom, makeClass, makeInt, makeLong, makeSessionKey, pastSpace, pickBits, pickBits, prettyPrint, readBlock, readInt, trimArrayLength, trimArrayLength, trimLeadingZeroes, writeBytes, writeBytes, writeInt |
| Methods inherited from class java.lang.Object |
getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.logi.crypto.keys.Key |
getFingerprint, getFingerprint, hashCode, matchFingerprint, matchFingerprint |
| Methods inherited from interface org.logi.crypto.io.PrettyPrintable |
prettyPrint |
| Methods inherited from interface java.security.Key |
getEncoded, getFormat |
| Constructor Detail |
public DHPrivateKey(java.math.BigInteger x,
java.math.BigInteger g,
java.math.BigInteger m)
x in the group modulo m with generator
g. It is a private key iff pri is
true.| Method Detail |
public static DHPrivateKey parseCDS(java.lang.String[] param)
throws InvalidCDSException
A valid CDS can be created by calling the toString() method.
InvalidCDSException - if the CDS is malformed.Crypto.fromString(String)public static java.math.BigInteger getModulus(int n)
Return the largest prime p < 2^n such
that (p-1)/2 is prime. This takes a long time unless
n is one of 256, 512, 1024 or 2048.
The reason for the second constraint on p is to make
the Discrete-Logarithm problem harder in the group Z_p. In
particular it thwarts the Pholig-Hellman algorithm.
public static java.math.BigInteger getGenerator(java.math.BigInteger m)
Returns the smallest number g > 1 with
gcd(g,m-1)=1.
public static KeyPair createKeys(int n)
n bit modulo.
Pre-calcualted modula exist for bit lengths 256, 512, 1024 and 2048. Using these values saves a lot of time and does not weaken the keys.
public static KeyPair createKeys(java.lang.String username,
java.lang.String password,
java.lang.String hashFunction,
int n)
throws InvalidCDSException
n bit modulo.
Pre-calcualted modula exist for bit lengths 256, 512, 1024 and 2048. Using these values saves a lot of time and does not weaken the keys.
public int getSize()
getSize in interface Keypublic java.lang.String getAlgorithm()
getAlgorithm in interface Keypublic boolean isPrivate()
public DHPublicKey getPublic()
public java.math.BigInteger getKey()
public java.math.BigInteger getM()
public java.math.BigInteger getG()
public final boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic boolean matches(Key key)
matches in interface Keypublic java.lang.String toString()
toString in class java.lang.Object
public void prettyPrint(java.io.PrintWriter out,
int ind,
int rec)
throws java.io.IOException
prettyPrint in interface PrettyPrintableprettyPrint in class Cryptopublic int plainBlockSize()
plainBlockSize in interface DecryptionKeypublic int cipherBlockSize()
cipherBlockSize in interface DecryptionKey
public void decrypt(byte[] source,
int i,
byte[] dest,
int j)
source starting at offset i and
plaintext is written to dest, starting at
offset j.
The amount of data read and written will match the values returned
by cipherBlockSize() and plainBlockSize().
decrypt in interface DecryptionKeypublic int signBlockSize()
signBlockSize in interface SigningKeypublic int signatureSize()
signatureSize in interface SigningKey
public Signature sign(Fingerprint fp)
throws KeyException
sign in interface SigningKeyKeyException - if the key modulus is shorter than the signature.KeyException - if this is not a private keypublic final Fingerprint getFingerprint()
getFingerprint in interface Key
public final Fingerprint getFingerprint(java.lang.String algorithm)
throws InvalidCDSException
getFingerprint in interface KeyInvalidCDSException - if the specified hash function is not
available.public Fingerprint matchFingerprint()
matchFingerprint in interface Key
public Fingerprint matchFingerprint(java.lang.String algorithm)
throws InvalidCDSException
matchFingerprint in interface KeyInvalidCDSException - if the specified hash function is not
available.public final int hashCode()
hashCode in interface KeyhashCode in class java.lang.Objectpublic byte[] getEncoded()
getEncoded in interface java.security.Keypublic java.lang.String getFormat()
getFormat in interface java.security.Key
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
Copyright (c) 1997-2001 Logi Ragnarsson - Distributed under the GPL