edu.vt.middleware.crypt.asymmetric
Class PublicKeyUtils

java.lang.Object
  extended by edu.vt.middleware.crypt.asymmetric.PublicKeyUtils

public final class PublicKeyUtils
extends Object

Utility methods for public and private keys used for asymmetric encryption.

Version:
$Revision: 2744 $
Author:
Middleware Services

Method Summary
static KeyPair generate(String algorithm, AlgorithmParameterSpec params)
          Generates a key pair with precise control over algorithm parameters.
static KeyPair generate(String algorithm, AlgorithmParameterSpec params, SecureRandom random)
          Generates a key pair with precise control over algorithm parameters.
static KeyPair generate(String algorithm, int bitLength)
          Generates a key pair of the given length with default algorithm parameters.
static KeyPair generate(String algorithm, int bitLength, SecureRandom random)
          Generates a key pair of the given length with default algorithm parameters.
static boolean isKeyPair(PublicKey pubKey, PrivateKey privKey)
          Determines whether the given public and private keys form a proper key pair by computing and verifying a digital signature with the keys.
static int length(PrivateKey privKey)
          Gets the length in bits of a private key where key size is dependent on the particulars of the algorithm.
static int length(PublicKey pubKey)
          Gets the length in bits of a public key where key size is dependent on the particulars of the algorithm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

length

public static int length(PublicKey pubKey)
Gets the length in bits of a public key where key size is dependent on the particulars of the algorithm.

Parameters:
pubKey - Public key.
Returns:
Size of the key in bits.

length

public static int length(PrivateKey privKey)
Gets the length in bits of a private key where key size is dependent on the particulars of the algorithm.

Parameters:
privKey - Private key.
Returns:
Size of the key in bits.

generate

public static KeyPair generate(String algorithm,
                               int bitLength)
                        throws CryptException
Generates a key pair of the given length with default algorithm parameters.

Parameters:
algorithm - Name of a cipher algorithm for which a suitable key pair will be generated.
bitLength - Size of each key in pair in bits.
Returns:
Key pair that may be used for encryption/decryption on a cipher of the given algorithm.
Throws:
CryptException - On key pair generation errors.

generate

public static KeyPair generate(String algorithm,
                               int bitLength,
                               SecureRandom random)
                        throws CryptException
Generates a key pair of the given length with default algorithm parameters.

Parameters:
algorithm - Name of a cipher algorithm for which a suitable key pair will be generated.
bitLength - Size of each key in pair in bits.
random - Source of randomness used for key generation.
Returns:
Key pair that may be used for encryption/decryption on a cipher of the given algorithm.
Throws:
CryptException - On key pair generation errors.

generate

public static KeyPair generate(String algorithm,
                               AlgorithmParameterSpec params)
                        throws CryptException
Generates a key pair with precise control over algorithm parameters.

Parameters:
algorithm - Name of a cipher algorithm for which a suitable key pair will be generated.
params - Algorithm-specific domain parameters.
Returns:
Key pair that may be used for encryption/decryption on a cipher of the given algorithm.
Throws:
CryptException - On key pair generation errors.

generate

public static KeyPair generate(String algorithm,
                               AlgorithmParameterSpec params,
                               SecureRandom random)
                        throws CryptException
Generates a key pair with precise control over algorithm parameters.

Parameters:
algorithm - Name of a cipher algorithm for which a suitable key pair will be generated.
params - Algorithm-specific domain parameters.
random - Source of randomness used for key generation.
Returns:
Key pair that may be used for encryption/decryption on a cipher of the given algorithm.
Throws:
CryptException - On key pair generation errors.

isKeyPair

public static boolean isKeyPair(PublicKey pubKey,
                                PrivateKey privKey)
Determines whether the given public and private keys form a proper key pair by computing and verifying a digital signature with the keys.

Parameters:
pubKey - Public key.
privKey - Private key.
Returns:
True if the keys form a compatible assymetric keypair, false otherwise. Errors during signature verification are treated as false.


Copyright © 2003-2013 Virginia Tech. All Rights Reserved.