bcgit / pc-dart

Pointy Castle - Dart Derived Bouncy Castle APIs
MIT License
241 stars 125 forks source link

How to get bytes from Signature? #217

Closed pedroserretti closed 11 months ago

pedroserretti commented 11 months ago

I'm trying to sign my XML, and i need the bytes from Signature object.

String arquivoXml = "...some xml string here..."
String sCert = "...some certificate string here..."

Uint8List dataBytes = Uint8List.fromList(utf8.encode(arquivoXml));
RSAPrivateKey rsaChavePrivada = CryptoUtils.rsaPrivateKeyFromPem(sCert);

final Signer signer = Signer('SHA-1/RSA')..init(true, PrivateKeyParameter<RSAPrivateKey>(rsaChavePrivada));
Signature signature = signer.generateSignature(dataBytes);

When debugging, signature have bytes in parameters, but i can't use it, how can i use the bytes from signature?

pedroserretti commented 11 months ago

To resolve i'm using basic_utils

String arquivoXml = "...some xml string here..."
String sCert = "...some certificate string here..."

Uint8List dataBytes = Uint8List.fromList(utf8.encode(arquivoXml));
RSAPrivateKey rsaChavePrivada = CryptoUtils.rsaPrivateKeyFromPem(sCert);

Uint8List assinatura = CryptoUtils.rsaSign(rsaChavePrivada, dataBytes, algorithmName: 'SHA-1/RSA');

final digestValue = crypto.sha1.convert(assinatura);
String signatureValue = base64.encode(assinatura);