rsaVerify static method

bool rsaVerify(
  1. RSAPublicKey publicKey,
  2. Uint8List signedData,
  3. Uint8List signature, {
  4. String algorithm = 'SHA-256/RSA',
})

Verifying the given signedData with the given publicKey and the given signature. Will return true if the given signature matches the signedData.

The default algorithm used is SHA-256/RSA. All supported algorihms are :

  • MD2/RSA
  • MD4/RSA
  • MD5/RSA
  • RIPEMD-128/RSA
  • RIPEMD-160/RSA
  • RIPEMD-256/RSA
  • SHA-1/RSA
  • SHA-224/RSA
  • SHA-256/RSA
  • SHA-384/RSA
  • SHA-512/RSA

Implementation

static bool rsaVerify(
    RSAPublicKey publicKey, Uint8List signedData, Uint8List signature,
    {String algorithm = 'SHA-256/RSA'}) {
  final sig = RSASignature(signature);

  final verifier = Signer(algorithm);

  verifier.init(false, PublicKeyParameter<RSAPublicKey>(publicKey));

  try {
    return verifier.verifySignature(signedData, sig);
  } on ArgumentError {
    return false;
  }
}