Class KeyConvertor
java.lang.Object
io.getlime.security.powerauth.crypto.lib.util.KeyConvertor
Key convertor for conversion of symmetric and asymmetric keys.
- Author:
- Petr Dvorak, petr@wultra.com, Roman Strobl, roman.strobl@wultra.com
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconvertBytesToPrivateKey(byte[] keyBytes) Convert a byte array to an EC private key by decoding the D number parameter (S in Java Security).convertBytesToPublicKey(byte[] keyBytes) Converts byte array to an EC public key, by decoding the Q point (W in Java Security).convertBytesToSharedSecretKey(byte[] bytesSecretKey) Converts a byte array to the secret shared key (usually used for AES based operations).convertPointBytesToPublicKey(byte[] xBytes, byte[] yBytes) Converts provided byte array representing X coordinate of an EC public key.byte[]convertPrivateKeyToBytes(PrivateKey privateKey) Converts an EC private key to bytes by encoding the D number parameter (S in Java Security).byte[]convertPublicKeyToBytes(PublicKey publicKey) Converts an EC public key to a byte array by encoding Q point parameter (W in Java Security).byte[]convertSharedSecretKeyToBytes(SecretKey sharedSecretKey) Converts a shared secret key (usually used for AES based operations) to a byte array.
-
Constructor Details
-
KeyConvertor
public KeyConvertor()
-
-
Method Details
-
convertPublicKeyToBytes
Converts an EC public key to a byte array by encoding Q point parameter (W in Java Security).- Parameters:
publicKey- An EC public key to be converted.- Returns:
- A byte array representation of the EC public key.
- Throws:
CryptoProviderException- When crypto provider is incorrectly initialized.
-
convertBytesToPublicKey
public PublicKey convertBytesToPublicKey(byte[] keyBytes) throws InvalidKeySpecException, CryptoProviderException, GenericCryptoException Converts byte array to an EC public key, by decoding the Q point (W in Java Security). parameter.- Parameters:
keyBytes- Bytes to be converted to EC public key.- Returns:
- An instance of the EC public key on success, or null on failure.
- Throws:
InvalidKeySpecException- When provided bytes are not a correct key representation.CryptoProviderException- When crypto provider is incorrectly initialized.GenericCryptoException- When public key is invalid.
-
convertPointBytesToPublicKey
public PublicKey convertPointBytesToPublicKey(byte[] xBytes, byte[] yBytes) throws InvalidKeySpecException, CryptoProviderException, GenericCryptoException Converts provided byte array representing X coordinate of an EC public key.- Parameters:
xBytes- X coordinate.yBytes- Y coordinate.- Returns:
- Public key with provided coordinates.
- Throws:
InvalidKeySpecException- When provided bytes are not a correct key representation.CryptoProviderException- When crypto provider is incorrectly initialized.GenericCryptoException- When public key is invalid.
-
convertPrivateKeyToBytes
Converts an EC private key to bytes by encoding the D number parameter (S in Java Security).- Parameters:
privateKey- An EC private key to be converted to bytes.- Returns:
- A byte array containing the representation of the EC private key.
-
convertBytesToPrivateKey
public PrivateKey convertBytesToPrivateKey(byte[] keyBytes) throws InvalidKeySpecException, CryptoProviderException Convert a byte array to an EC private key by decoding the D number parameter (S in Java Security).- Parameters:
keyBytes- Bytes to be converted to the EC private key.- Returns:
- An instance of EC private key decoded from the input bytes.
- Throws:
InvalidKeySpecException- The provided key bytes are not a valid EC private key.CryptoProviderException- When crypto provider is incorrectly initialized.
-