Ephenodrom / Dart-Basic-Utils

A dart package for many helper methods fitting common situations
MIT License
364 stars 77 forks source link

feat: Add optional ECDomainParameters to ec key from bytes method #95

Closed krille-chan closed 1 year ago

krille-chan commented 1 year ago

Good morning ❤️ first of all thank you very much for your library. While playing around with it I ran into the problem that I wasn't able to import private/public ec keys when they use the curve brainpoolP256r1. I've got the error message from pointycastle: No algorithm registered of type ECDomainParameters with name: brainpoolP256r1"

After some investigation I found out that this should be fixable by specifying this curve as a parameter first and use it in the constructor of the ECPrivateKey and ECPublicKey classes like this:

final parameters = ECCurve_brainpoolp256r1();
final key = ECPrivateKey(
      osp2i(x),
      parameters,
);

So I added two optional parameters to the CryptoUtils.ecPrivateKeyFromDerBytes() and CryptoUtils.ecPublicKeyFromDerBytes() methods to overwrite the ECDomainParameters for special EC Curves which worked fine for me locally. I thought the ***KeyFromDerBytes() methods looked like a good place as they already have the bool pkcs8 optional parameter.

Ephenodrom commented 1 year ago

@krille-chan This looks good so far. Will try to release an update on pub.dev this week.