net.i2p.crypto
Class KeyGenerator

java.lang.Object
  extended by net.i2p.crypto.KeyGenerator

public class KeyGenerator
extends Object

Define a way of generating asymmetrical key pairs as well as symmetrical keys

Author:
jrandom

Field Summary
static int PUBKEY_EXPONENT_SIZE
          Deprecated. use getElGamalExponentSize() which allows override in the properties
 
Constructor Summary
KeyGenerator(I2PAppContext context)
           
 
Method Summary
 Object[] generatePKIKeypair()
          Generate a pair of keys, where index 0 is a PublicKey, and index 1 is a PrivateKey
 SimpleDataStructure[] generatePKIKeys()
          Same as above but different return type
 SessionKey generateSessionKey()
          Generate a private 256 bit session key
 SessionKey generateSessionKey(byte[] salt, byte[] passphrase)
          PBE the passphrase with the salt.
 Object[] generateSigningKeypair()
          Generate a pair of DSA keys, where index 0 is a SigningPublicKey, and index 1 is a SigningPrivateKey.
 SimpleDataStructure[] generateSigningKeys()
          DSA-SHA1 only.
 SimpleDataStructure[] generateSigningKeys(SigType type)
          Generic signature type, supports DSA and ECDSA
 int getElGamalExponentSize()
           
static KeyGenerator getInstance()
           
static PublicKey getPublicKey(PrivateKey priv)
          Convert a PrivateKey to its corresponding PublicKey
static SigningPublicKey getSigningPublicKey(SigningPrivateKey priv)
          Convert a SigningPrivateKey to a SigningPublicKey.
static void main(String[] args)
          Usage: KeyGenerator [sigtype...]
 boolean useLongElGamalExponent()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PUBKEY_EXPONENT_SIZE

public static final int PUBKEY_EXPONENT_SIZE
Deprecated. use getElGamalExponentSize() which allows override in the properties
Constructor Detail

KeyGenerator

public KeyGenerator(I2PAppContext context)
Method Detail

getInstance

public static KeyGenerator getInstance()

generateSessionKey

public SessionKey generateSessionKey()
Generate a private 256 bit session key

Returns:
session key

generateSessionKey

public SessionKey generateSessionKey(byte[] salt,
                                     byte[] passphrase)
PBE the passphrase with the salt. Warning - SLOW Deprecated - Used by Syndie only.


useLongElGamalExponent

public boolean useLongElGamalExponent()
Since:
0.9.8

getElGamalExponentSize

public int getElGamalExponentSize()
Since:
0.9.8

generatePKIKeypair

public Object[] generatePKIKeypair()
Generate a pair of keys, where index 0 is a PublicKey, and index 1 is a PrivateKey

Returns:
pair of keys

generatePKIKeys

public SimpleDataStructure[] generatePKIKeys()
Same as above but different return type

Since:
0.8.7

getPublicKey

public static PublicKey getPublicKey(PrivateKey priv)
Convert a PrivateKey to its corresponding PublicKey

Parameters:
priv - PrivateKey object
Returns:
the corresponding PublicKey object
Throws:
IllegalArgumentException - on bad key

generateSigningKeypair

public Object[] generateSigningKeypair()
Generate a pair of DSA keys, where index 0 is a SigningPublicKey, and index 1 is a SigningPrivateKey. DSA-SHA1 only.

Returns:
pair of keys

generateSigningKeys

public SimpleDataStructure[] generateSigningKeys()
DSA-SHA1 only. Same as above but different return type

Since:
0.8.7

generateSigningKeys

public SimpleDataStructure[] generateSigningKeys(SigType type)
                                          throws GeneralSecurityException
Generic signature type, supports DSA and ECDSA

Throws:
GeneralSecurityException
Since:
0.9.9

getSigningPublicKey

public static SigningPublicKey getSigningPublicKey(SigningPrivateKey priv)
Convert a SigningPrivateKey to a SigningPublicKey. As of 0.9.16, supports all key types.

Parameters:
priv - a SigningPrivateKey object
Returns:
a SigningPublicKey object
Throws:
IllegalArgumentException - on bad key or unknown type

main

public static void main(String[] args)
Usage: KeyGenerator [sigtype...]