Class KeyConvertor

java.lang.Object
io.getlime.security.powerauth.crypto.lib.util.KeyConvertor

public class KeyConvertor extends Object
Key convertor for conversion of symmetric and asymmetric keys.
Author:
Petr Dvorak, petr@wultra.com, Roman Strobl, roman.strobl@wultra.com
  • Constructor Details

    • KeyConvertor

      public KeyConvertor()
  • Method Details

    • convertPublicKeyToBytes

      public byte[] convertPublicKeyToBytes(PublicKey publicKey) throws CryptoProviderException
      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

      public byte[] convertPrivateKeyToBytes(PrivateKey privateKey)
      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.
    • convertSharedSecretKeyToBytes

      public byte[] convertSharedSecretKeyToBytes(SecretKey sharedSecretKey)
      Converts a shared secret key (usually used for AES based operations) to a byte array.
      Parameters:
      sharedSecretKey - A shared key to be converted to bytes.
      Returns:
      A byte array representation of the shared secret key.
    • convertBytesToSharedSecretKey

      public SecretKey convertBytesToSharedSecretKey(byte[] bytesSecretKey)
      Converts a byte array to the secret shared key (usually used for AES based operations).
      Parameters:
      bytesSecretKey - Bytes representing the shared key.
      Returns:
      An instance of the secret key by decoding from provided bytes.