Class SignatureUtils

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

public class SignatureUtils extends Object
Utility class for signature calculation and validation used both on client and server.
Author:
Petr Dvorak
  • Constructor Details

    • SignatureUtils

      public SignatureUtils()
  • Method Details

    • computeECDSASignature

      public byte[] computeECDSASignature(byte[] bytes, PrivateKey masterPrivateKey) throws InvalidKeyException, GenericCryptoException, CryptoProviderException
      Compute ECDSA signature of given bytes with a private key.
      Parameters:
      bytes - Bytes to be signed.
      masterPrivateKey - Private key for computing the signature.
      Returns:
      Signature for given data.
      Throws:
      InvalidKeyException - In case invalid key was provided.
      GenericCryptoException - In case signature calculation fails.
      CryptoProviderException - In case cryptography provider is incorrectly initialized.
    • computeECDSASignature

      public byte[] computeECDSASignature(byte[] bytes, PrivateKey masterPrivateKey, SecureRandom secureRandom) throws InvalidKeyException, GenericCryptoException, CryptoProviderException
      Compute ECDSA signature of given bytes with a private key, using a provided instance of SecureRandom.
      Parameters:
      bytes - Bytes to be signed.
      masterPrivateKey - Private key for computing the signature.
      secureRandom - Secure random instance.
      Returns:
      Signature for given data.
      Throws:
      InvalidKeyException - In case invalid key was provided.
      GenericCryptoException - In case signature calculation fails.
      CryptoProviderException - In case cryptography provider is incorrectly initialized.
    • validateECDSASignature

      public boolean validateECDSASignature(byte[] signedBytes, byte[] signature, PublicKey masterPublicKey) throws InvalidKeyException, GenericCryptoException, CryptoProviderException
      Validate an ECDSA signature against given data using a public key.
      Parameters:
      signedBytes - Bytes that are signed.
      signature - Signature of the bytes.
      masterPublicKey - Public key for validating the signature.
      Returns:
      Returns "true" if signature matches, "false" otherwise.
      Throws:
      InvalidKeyException - In case invalid key was provided.
      GenericCryptoException - In case signature calculation fails.
      CryptoProviderException - In case cryptography provider is incorrectly initialized.
    • computePowerAuthSignature

      public String computePowerAuthSignature(byte[] data, List<SecretKey> signatureKeys, byte[] ctrData, SignatureConfiguration configuration) throws GenericCryptoException, CryptoProviderException
      Compute PowerAuth signature for given data using a secret signature keys and counter byte array.
      Parameters:
      data - Data to be signed.
      signatureKeys - Keys for computing the signature.
      ctrData - Counter byte array / derived key index.
      configuration - Format of signature to produce and parameters for the signature.
      Returns:
      PowerAuth signature for given data.
      Throws:
      GenericCryptoException - In case signature computation fails.
      CryptoProviderException - In case cryptography provider is incorrectly initialized.
    • validatePowerAuthSignature

      public boolean validatePowerAuthSignature(byte[] data, String signature, List<SecretKey> signatureKeys, byte[] ctrData, SignatureConfiguration configuration) throws GenericCryptoException, CryptoProviderException
      Validate the PowerAuth signature for given data using provided keys.
      Parameters:
      data - Data that were signed.
      signature - Data signature.
      signatureKeys - Keys for signature validation.
      ctrData - Counter data.
      configuration - Format in which signature will be validated and parameters for the validation.
      Returns:
      Return "true" if signature matches, "false" otherwise.
      Throws:
      GenericCryptoException - In case signature computation fails.
      CryptoProviderException - In case cryptography provider is incorrectly initialized.