verify method

bool verify(
  1. dynamic value,
  2. dynamic signature
)

Verifies the value and the signature.

Implementation

bool verify(dynamic value, dynamic signature) {
  if (_publicKey == null) {
    throw Exception(
      'RSA attempted to verify but [publicKey] is null',
    );
  }
  final signer = Signer(RSASigner(
    _digest,
    publicKey: _publicKey,
  ));

  List<int> bytes;
  Uint8List sigBytes;

  if (value == null) {
    throw Exception('Required value is null');
  } else if (value is List<int>) {
    bytes = value;
  } else if (value is Uint8List) {
    bytes = value.toList();
  } else if (value is String) {
    bytes = utf8.encode(value);
  } else {
    bytes = utf8.encode(value.toString());
  }

  if (signature == null) {
    throw Exception('Required signature is null');
  } else if (signature is List<int>) {
    sigBytes = Uint8List.fromList(signature);
  } else if (signature is Uint8List) {
    sigBytes = signature;
  } else if (signature is String) {
    sigBytes = base64.decode(signature);
  } else {
    sigBytes = base64.decode(signature.toString());
  }

  return signer.verifyBytes(bytes, Encrypted(sigBytes));
}