public void CreateECKeySerializeDeserializeSignAndVerify(KeyStrength keyStrength) { var parameters = ECDsaHelper.CreateNewECDsaParameters(keyStrength); var key = new TagPubECKey(parameters); var bytes = key.EncodedBytes; TestContext.WriteLine(bytes.AsLiteral()); using var ms = new MemoryStream(bytes); var tag = ms.Decode <TagPubKey>(); Assert.NotNull(tag); Assert.AreEqual(key, tag); CollectionAssert.AreEqual(bytes, tag.EncodedBytes); var signatureBytes = ECDsaHelper.HashAndSign(bytes, parameters.Parameters, parameters.HashAlgorithm.ToName()); var signature = new TagSignature(Algorithm.EcDSA, signatureBytes); Assert.IsTrue(key.Verify(bytes, signature), "Signature failed!"); }
public override TagSignature SignAndUpdate(byte[] data, Func <byte[], byte[]> encrypt = null) => Update(encrypt, ECDsaHelper.HashAndSign(data, _keyParameters.Parameters, HashAlgorithmName.SHA256));