public class KeyGenerator extends Object
| Constructor and Description |
|---|
KeyGenerator() |
| Modifier and Type | Method and Description |
|---|---|
SecretKey |
computeSharedKey(PrivateKey privateKey,
PublicKey publicKey)
Computes a pre-shared key for given private key and public key (ECDH).
|
byte[] |
convert32Bto16B(byte[] original)
Convert 32B byte long array to 16B long array by applying xor between first half and second half values.
|
SecretKey |
deriveSecretKey(SecretKey secret,
long index)
Derives a new secret key KEY_SHARED from a master secret key KEY_MASTER
based on following KDF:
BYTES = index, padded from left with 0x00, total 16 bytes
KEY_SHARED[BYTES] = AES(BYTES, KEY_MASTER)
|
SecretKey |
deriveSecretKeyFromPassword(String password,
byte[] salt)
Derive a long AES suitable key from a password and salt.
|
KeyPair |
generateKeyPair()
Generate a new ECDH key pair using P256r1 curve.
|
byte[] |
generateRandomBytes(int len)
Generate a new random byte array with given length.
|
SecretKey |
generateRandomSecretKey()
Generate a new random symmetric key.
|
public KeyPair generateKeyPair()
public SecretKey computeSharedKey(PrivateKey privateKey, PublicKey publicKey) throws InvalidKeyException
privateKey - A private key.publicKey - A public key.InvalidKeyException - One of the provided keys are not valid keys.public byte[] convert32Bto16B(byte[] original)
throws IllegalArgumentException
original - Original byte array, 32B long.IllegalArgumentExceptionpublic byte[] generateRandomBytes(int len)
len - Number of random bytes to be generated.public SecretKey generateRandomSecretKey()
public SecretKey deriveSecretKey(SecretKey secret, long index)
secret - A master shared keyindex - An index of the keypublic SecretKey deriveSecretKeyFromPassword(String password, byte[] salt)
password - A password used for key derivationsalt - A salt used for key derivationCopyright © 2016 Lime - HighTech Solutions Inc.. All rights reserved.