I would like to verify a signature with a public key and can't find any way to do this in dart. In Swift, there is an easy solution via the SecKeyVerifySignature
function. Is there something similar in flutter? I could only find the cryptography library but that won't let me set my own public key. Is there any way to archive this? Thanks in advance.
Asked
Active
Viewed 827 times
0

Paul
- 177
- 2
- 9
1 Answers
0
Use the pointycastle
package. ECDSASigner
is initialized with an ECPublicKey
..
final verifier = ECDSASigner(SHA256Digest())
..init(
false, // verify vs sign
PublicKeyParameter(key), // key is an ECPublicKey
);
verifier.verifySignature(message, signature);

Richard Heap
- 48,344
- 9
- 130
- 112
-
Thanks. I have extracted my public key from a certificate via the ASN1Parser. So it is saved in a List
. Is there a way to convert that list to an ECPublicKey? – Paul Jun 23 '21 at 14:50 -
Check out the `basic_utils` package and its method: `ECPublicKey ecPublicKeyFromDerBytes(Uint8List bytes);` – Richard Heap Jun 24 '21 at 00:16
-
It'll do the ASN.1 bits for you too, I think - check the `fromPem()` versions – Richard Heap Jun 24 '21 at 00:17
-
Did that help?? – Richard Heap Jun 25 '21 at 00:10
-
Some, there is a function called ```CryptoUtils.ecPublicKeyFromPem(String pem)```but it gives me the Error: ```_CastError (type 'ASN1Integer' is not a subtype of type 'ASN1ObjectIdentifier' in type cast)``` – Paul Jun 25 '21 at 17:16
-
It seems like the problem is the curve ```1.2.840.10045.4.3.2 ecdsaWithSHA256 (ANSI X9.62 ECDSA algorithm with SHA256)```. It isn't included in the package. Is there a way to implement that? – Paul Jun 25 '21 at 21:08
-
Are you able to update the question with the certificate PEM? – Richard Heap Jun 28 '21 at 16:30