public final class KeyGenUtils
extends java.lang.Object
| Constructor and Description |
|---|
KeyGenUtils() |
| Modifier and Type | Method and Description |
|---|---|
static javax.crypto.spec.IvParameterSpec |
deriveIvParameterSpec(javax.crypto.SecretKey kdfKey,
java.lang.Class<?> c,
java.lang.String kdfString,
KeyType ivType)
Derives a IvParameterSpec of the specified type from the given key using the provided class
name and kdfString
|
static javax.crypto.SecretKey |
deriveSecretKey(javax.crypto.SecretKey kdfKey,
java.lang.Class<?> c,
java.lang.String kdfString,
KeyType type)
Derives a SecretKey of the specified type from the given key using the provided class name
and kdfString
|
static javax.crypto.spec.IvParameterSpec |
genIV(int length)
Generates a random iv of a specified length
|
static java.security.KeyPair |
genKeyPair(KeyPairType type)
Generates a public/private key pair formatted for the algorithm specified
and stores the keys in a KeyPair.
|
static java.nio.ByteBuffer |
genNonce(int length)
Generates a random nonce of a specified length
|
static javax.crypto.SecretKey |
genSecretKey(KeyType type)
Generates a secret key for the specified symmetric algorithm
|
static javax.crypto.spec.IvParameterSpec |
getIvParameterSpec(byte[] iv,
int offset,
int length)
Converts an iv in a specified portion of a byte[] and places it in a IvParameterSpec.
|
static javax.crypto.spec.IvParameterSpec |
getIvParameterSpec(java.nio.ByteBuffer iv)
Converts an iv in a ByteBuffer and places it in a IvParameterSpec.
|
static java.security.KeyPair |
getKeyPair(KeyPairType type,
byte[] pub,
byte[] pri)
Converts the specified keys for a specified algorithm to PrivateKey and PublicKey
respectively.
|
static java.security.KeyPair |
getKeyPair(KeyPairType type,
java.nio.ByteBuffer pub,
java.nio.ByteBuffer pri)
Converts the specified keys for a specified algorithm to PrivateKey and PublicKey
respectively.
|
static java.security.KeyPair |
getKeyPair(java.security.PublicKey pubK,
java.security.PrivateKey privK)
Takes the PublicKey and PrivateKey and stores them in a KeyPair
|
static java.security.PublicKey |
getPublicKey(KeyPairType type,
byte[] pub)
Converts a specified key for a specified algorithm to a PublicKey.
|
static java.security.PublicKey |
getPublicKey(KeyPairType type,
java.nio.ByteBuffer pub)
Converts a specified key for a specified algorithm to a PublicKey.
|
static java.security.KeyPair |
getPublicKeyPair(KeyPairType type,
byte[] pub)
Converts a specified key for a specified algorithm to a PublicKey which is then stored in
a KeyPair.
|
static java.security.KeyPair |
getPublicKeyPair(KeyPairType type,
java.nio.ByteBuffer pub)
Converts a specified key for a specified algorithm to a PublicKey which is then stored in
a KeyPair.
|
static javax.crypto.SecretKey |
getSecretKey(KeyType type,
byte[] key)
Converts the specified key into a SecretKey for the specified algorithm.
|
static javax.crypto.SecretKey |
getSecretKey(KeyType type,
java.nio.ByteBuffer key)
Converts the specified key into a SecretKey for the specified algorithm
|
public static java.security.KeyPair genKeyPair(KeyPairType type)
type - The algorithm format that the key pair should be generated for.public static java.security.PublicKey getPublicKey(KeyPairType type, byte[] pub)
type - The type of key being passed inpub - Public key as byte[]public static java.security.PublicKey getPublicKey(KeyPairType type, java.nio.ByteBuffer pub)
type - The type of key being passed inpub - Public key as ByteBufferpublic static java.security.KeyPair getPublicKeyPair(KeyPairType type, byte[] pub)
type - The type of key being passed inpub - Public key as byte[]public static java.security.KeyPair getPublicKeyPair(KeyPairType type, java.nio.ByteBuffer pub)
type - The type of key being passed inpub - Public key as ByteBufferpublic static java.security.KeyPair getKeyPair(KeyPairType type, byte[] pub, byte[] pri)
type - The type of key being passed inpub - Public key as byte[]pri - Private key as byte[]public static java.security.KeyPair getKeyPair(KeyPairType type, java.nio.ByteBuffer pub, java.nio.ByteBuffer pri)
type - The type of key being passed inpub - Public key as ByteBufferpri - Private key as ByteBufferpublic static java.security.KeyPair getKeyPair(java.security.PublicKey pubK,
java.security.PrivateKey privK)
pubK - Public key as PublicKeyprivK - Private key as PrivateKeypublic static javax.crypto.SecretKey genSecretKey(KeyType type)
type - Type of key to generatepublic static javax.crypto.SecretKey getSecretKey(KeyType type, byte[] key)
key - The byte[] of the keytype - Type of keypublic static javax.crypto.SecretKey getSecretKey(KeyType type, java.nio.ByteBuffer key)
key - The ByteBuffer of the keytype - Type of keypublic static java.nio.ByteBuffer genNonce(int length)
length - How long the nonce should bepublic static javax.crypto.spec.IvParameterSpec genIV(int length)
length - How long the iv should be in bytespublic static javax.crypto.spec.IvParameterSpec getIvParameterSpec(byte[] iv,
int offset,
int length)
iv - The byte[] containing the ivoffset - Where the iv beginslength - How long the iv ispublic static javax.crypto.spec.IvParameterSpec getIvParameterSpec(java.nio.ByteBuffer iv)
iv - The ByteBuffer containing the ivpublic static javax.crypto.SecretKey deriveSecretKey(javax.crypto.SecretKey kdfKey,
java.lang.Class<?> c,
java.lang.String kdfString,
KeyType type)
throws java.security.InvalidKeyException
kdfKey - The key to derive fromc - Class name to use in derivationkdfString - String to use in derivationtype - The type of key to derivejava.security.InvalidKeyExceptionpublic static javax.crypto.spec.IvParameterSpec deriveIvParameterSpec(javax.crypto.SecretKey kdfKey,
java.lang.Class<?> c,
java.lang.String kdfString,
KeyType ivType)
throws java.security.InvalidKeyException
kdfKey - The key to derive fromc - Class name to use in derivationkdfString - String to use in derivationivType - The type of IV to derivejava.security.InvalidKeyException