Exemplo n.º 1
0
 private static void PrintCoinRequest(CoinRequest coinRequest)
 {
     Console.WriteLine("MESSAGE TO BE SIGNED BY THE BANK:");
     Console.WriteLine("");
     Console.WriteLine(Base64.ToBase64String(coinRequest.GetMessage()));
     Console.WriteLine("");
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Blinding.CanVerifyBlind();
            // Create a "protocoin" using the bank's public key. The protocoin
            // contains an internal blinding factor that is used to blind the
            // message to be signed by the bank.
            Protocoin protocoin = new Protocoin(bank.GetPublic());

            // Generate a coin request.
            CoinRequest coinRequest = protocoin.GenerateCoinRequest();

            PrintCoinRequest(coinRequest);

            // Ask the bank to sign the coin request.

            // Note: In practice the bank will be on a remote server and this will
            // be an asynchronous operation. The bank will verify Alice's
            // credentials and debit her account for every coin it issues.
            // Needless to say, the connection to the bank would have to be over a
            // secure channel.

            byte[] signature = bank.Sign(coinRequest);

            PrintBankSignature(signature);

            // Create a new coin using the bank's signature.
            Coin coin = protocoin.CreateCoin(signature);

            PrintCoin(coin);

            // The signature on the coin is different from the one the bank
            // returned earlier (magic!). Will the bank accept the coin as valid?
            // Let's see ...
            bool valid = bank.Verify(coin);

            if (valid)
            {
                // It should always print "OK"
                Console.WriteLine("OK");
            }
            else
            {
                Console.WriteLine("Fail!");
            }

            Console.ReadKey();
        }