konstantinullrich / crypton

A simple Dart library for asymmetric encryption and digital signatures
https://pub.dev/packages/crypton
MIT License
34 stars 12 forks source link

Verification of the digital signature using EC key failed #44

Open jifang opened 11 months ago

jifang commented 11 months ago
import 'dart:typed_data';

import 'package:crypton/crypton.dart';

main() {
  ECKeypair ecKeypair = ECKeypair.fromRandom();
  for (int i = 0; i < 100; i++) {
    String message = i.toRadixString(16);
    final List<int> codeUnits = message.codeUnits;
    final Uint8List unit8List = Uint8List.fromList(codeUnits);
    final signature = ecKeypair.privateKey.createSHA256Signature(unit8List);
    bool verified = ecKeypair.publicKey.verifySHA256Signature(unit8List, signature);
    if (!verified) {
      print('verified failed: $unit8List');
    }
  }
}

On average, the fail rate is about 5%. RSAKey seems fine though.

konstantinullrich commented 11 months ago

Hmm, that seems wired. I'm gonna look into it