예제 #1
0
 private TagSignature Update(Func <byte[], byte[]> encrypt, byte[] signatureData)
 {
     if (_destroyKeysAfterSigning)
     {
         _keyParameters        = null;
         _nextKeyParameters    = null;
         _data.Value.Encrypted = null;
         _data.Value.PublicKey = null;
     }
     else
     {
         var encryptionHandler = encrypt.Required();
         if (_nextKeyParameters != null)
         {
             _keyParameters                 = _nextKeyParameters;
             _data.Value.Encrypted          = encryptionHandler(_keyParameters.EncodedBytes);
             _data.Value.PublicKey          = NextPublicKey;
             _nextKeyParameters             = null;
             _data.SignaturesWithCurrentKey = 0;
         }
         else
         {
             _data.SignaturesWithCurrentKey++;
         }
         _data.LastSignatureTimeStamp = _timeStamper.Now;
     }
     _data.Changed();
     return(new TagSignature(Algorithm.EcDSA, signatureData));
 }
    public static ECDsaParameters CreateNewECDsaParameters(KeyStrength strength)
    {
        using var provider = ECDsa.Create();
        var curve = ECDsaParameters.ChooseCurve(strength);

        provider.GenerateKey(curve);
        return(new ECDsaParameters(provider.ExportParameters(true), strength, ECDsaParameters.ChooseHashAlgo(curve)));
    }
 private static bool VerifyStream(Stream dataStream, TagSignature signature, ECParameters parameters)
 {
     try {
         if (signature.Required().Algorithm != Algorithm.EcDSA)
         {
             throw new InvalidDataException($"Signature uses different algorithm {signature.Algorithm} from this ECDsa key!");
         }
         if (parameters.D == null)
         {
             throw new InvalidDataException($"This ECDsa key is not properly configured to be able to verify a signature!");
         }
         using var algo = OpenWith(parameters);
         return(algo.VerifyData(dataStream, signature.Data, ECDsaParameters.ChooseHashAlgo(parameters.Curve).ToName()));
     } catch (CryptographicException e) {
         throw new InterlockLedgerCryptographicException("Failed to verify data with current parameters and signature", e);
     }
 }
예제 #4
0
 public TagPubECKey(ECDsaParameters parameters) : base(Algorithm.EcDSA, parameters.EncodedPublicBytes) => _kp = parameters;