Ejemplo n.º 1
0
        public void SignTransaction(Key signingKey)
        {
            if (signingKey.PublicKey != FromAddress)
            {
                throw new Exception("You cannot sign transactions for other wallets!");
            }

            var hashTx = HashGenerator.CalculateHash(FromAddress + ToAddress + Amount + signingKey.PublicKey);

            Signature = hashTx;
        }
Ejemplo n.º 2
0
        protected Int32 GenerateConfigId(EndpointConfiguration config)
        {
            Int64 result = config.RootDeviceDescriptionPathsToRootDevices.Values.Select(
                rootDevice => rootDevice.BuildRootDeviceDescription(
                    _serverData, config, CultureInfo.InvariantCulture)).Aggregate <string, long>(
                0, (current, description) => current + HashGenerator.CalculateHash(0, description));

            result = config.SCPDPathsToServices.Values.Select(service => service.BuildSCPDDocument(
                                                                  config, _serverData)).Aggregate(result, (current, description) => current + HashGenerator.CalculateHash(0, description));
            result += HashGenerator.CalculateHash(0, NetworkHelper.IPAddrToString(config.EndPointIPAddress));
            //result += HashGenerator.CalculateHash(0, config.ServicePrefix);
            result += HashGenerator.CalculateHash(0, config.ControlPathBase + config.DescriptionPathBase + config.EventSubPathBase);
            return((int)result);
        }
Ejemplo n.º 3
0
        public bool IsValid()
        {
            if (string.IsNullOrEmpty(FromAddress))
            {
                return(true);
            }

            if (string.IsNullOrEmpty(Signature) || Signature.Length == 0)
            {
                throw new Exception("No signature in this transaction");
            }

            var hashTx = HashGenerator.CalculateHash(FromAddress + ToAddress + Amount + FromAddress);

            return(hashTx == Signature);
        }
Ejemplo n.º 4
0
        public string GetKey()
        {
            var           rsa        = new RSACryptoServiceProvider(1024);
            RSAParameters parameters = rsa.ExportParameters(true);
            Key           key        = new Key(HashGenerator.CalculateHash(Convert.ToBase64String(parameters.D)));

            key.PublicKey =
                HashGenerator.CalculateHash(key.PrivateKey + parameters.D + parameters.DP + parameters.DQ +
                                            parameters.Exponent);
            Transaction tx = new Transaction(TestWalletAddress, key.PublicKey, 50);

            tx.SignTransaction(new Key()
            {
                PrivateKey = TestKey, PublicKey = TestWalletAddress
            });
            KevCoin.AddTransaction(tx);
            // KevCoin.MinePendingTransactions(TestWalletAddress);
            return($"Private key: {key.PrivateKey}" +
                   $"\nPublic key: {key.PublicKey}" +
                   $"\nYour free reward of 50 coins is added to pending transactions.");
        }
Ejemplo n.º 5
0
 public string CalculateHash()
 {
     return(HashGenerator.CalculateHash($"{this.Node} + {this.PreviousHash} + {this.TimeStamp} + {JsonConvert.SerializeObject(this.Data) + this.Nonce}"));
 }
Ejemplo n.º 6
0
 public string CalculateHash()
 {
     return(HashGenerator.CalculateHash(Timestamp + Transactions.ToString() + PreviousHash + Nonce));
 }