Esempio n. 1
0
 public IActionResult HashTransaction(
     [FromServices] ITransactionHasher transactionHasher,
     Transaction transaction
     )
 {
     return(Ok(new {
         Hash = transactionHasher.HashTransaction(transaction),
         Algorithm = transactionHasher.HashAlgorithm
     }));
 }
Esempio n. 2
0
        public bool TryValidateTransaction(Transaction transaction)
        {
            using (var rsa = RSA.Create())
            {
                rsa.ImportRSAPublicKey(transaction.SenderWalletID, out var bytesRead);
                var hash = _iTransactionHasher.HashTransaction(transaction);

                RSAPKCS1SignatureDeformatter vaildator = new RSAPKCS1SignatureDeformatter(rsa);
                vaildator.SetHashAlgorithm(_iTransactionHasher.HashAlgorithm);

                return(vaildator.VerifySignature(hash, transaction.Signature));
            }
        }
Esempio n. 3
0
        public Transaction SignTransaction(Transaction transaction, Key key)
        {
            _iFeatureProvider.Gaurd(FeatureToggles.Crypto.EnableTransactionSigning);

            using (var rsa = RSA.Create())
            {
                rsa.ImportRSAPrivateKey(key.PrivateKey, out var bytesRead);
                var hash = _iTransactionHasher.HashTransaction(transaction);

                RSAPKCS1SignatureFormatter signer = new RSAPKCS1SignatureFormatter(rsa);
                signer.SetHashAlgorithm(_iTransactionHasher.HashAlgorithm);
                transaction.Signature = signer.CreateSignature(hash);

                return(transaction);
            }
        }