I am working on an E voting system based on Foo92 protocol. I am new to Bouncy Castle library. But I have to tell that this system based on blind signature with RSA Algorithm. This Scheme(FOO92) has a chart and I have Upload it for you. I want to know that how to sign blindly and verify it in Bouncy Castle library. Please Help me with my problem. Thank you All. enter image description here

Please Notice that * operator is blinding operator. and / operator is unblinding operator.

有帮助吗?

解决方案

Finally I have wrote a code with Bouncy Castle for FOO92 e-voting protocol. Here is the Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Org.BouncyCastle;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.OpenSsl;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Crypto.Signers;
using Org.BouncyCastle.Crypto.Digests;
using System.Windows.Forms;

namespace FooTest
{
    class FooImplementing
    {
        private RsaBlindingEngine rsaBlindingEngine = new RsaBlindingEngine();
        private RsaBlindingFactorGenerator blindingFactorGenerator = new RsaBlindingFactorGenerator();
        private RsaBlindingParameters blindingParameteres;
        private RsaKeyPairGenerator aliceRsaKeyGenerator = new RsaKeyPairGenerator();
        private AsymmetricCipherKeyPair aliceKeyPair;
        private RsaKeyPairGenerator bobRsaKeyGenerator = new RsaKeyPairGenerator();
        private AsymmetricCipherKeyPair bobKeyPair;
        private byte[] inputMessage;
        public FooImplementing(string message)
        {
            inputMessage = getBytes(message);
            aliceRsaKeyGenerator.Init(new KeyGenerationParameters(new SecureRandom(), 1024));
            aliceKeyPair = aliceRsaKeyGenerator.GenerateKeyPair();
            //******************************************************************************
            bobRsaKeyGenerator.Init(new KeyGenerationParameters(new SecureRandom(), 1024));
            bobKeyPair = bobRsaKeyGenerator.GenerateKeyPair();
            //******************************************************************************
            blindingFactorGenerator.Init(bobKeyPair.Public);
            blindingParameteres = new RsaBlindingParameters((RsaKeyParameters)bobKeyPair.Public, blindingFactorGenerator.GenerateBlindingFactor());
        }

        public byte[] getBytes(string input)
        {
            byte[] bytes = new byte[input.Length * sizeof(char)];
            System.Buffer.BlockCopy(input.ToCharArray(), 0, bytes, 0, bytes.Length);
            return bytes;
        }

        public string GetString(byte[] bytes)
        {
            char[] chars = new char[bytes.Length / sizeof(char)];
            System.Buffer.BlockCopy(bytes, 0, chars, 0, bytes.Length);
            return new string(chars);
        }

        public byte[] blindTheMessage(TextBox t1)
        {
            for (int i = 0; i < inputMessage.Length; i++)
            {
                t1.Text += inputMessage[i].ToString();
            }
            PssSigner messageBlinder = new PssSigner(rsaBlindingEngine, new Sha1Digest(), 15);
            messageBlinder.Init(true, blindingParameteres);
            messageBlinder.BlockUpdate(inputMessage, 0, inputMessage.Length);
            byte[] blindedMessage = messageBlinder.GenerateSignature();
            return blindedMessage;
        }

        public byte[] blindSignature(byte[] input)
        {
            RsaEngine rsaEngine = new RsaEngine();
            rsaEngine.Init(true, bobKeyPair.Private);
            byte[] blindSignedMessage = rsaEngine.ProcessBlock(input, 0, input.Length);
            return blindSignedMessage;
        }

        public byte[] unblindeTheSignedData(byte[] input)
        {
            rsaBlindingEngine.Init(false, blindingParameteres);
            byte[] messageForSending = rsaBlindingEngine.ProcessBlock(input, 0, input.Length);
            return messageForSending;
        }

        public bool verifyBlindSignature(byte[] input, TextBox t1)
        {            
            PssSigner verifier = new PssSigner(new RsaEngine(), new Sha1Digest(), 15);
            verifier.Init(false, bobKeyPair.Public);
            verifier.BlockUpdate(inputMessage, 0, inputMessage.Length);
            for (int i = 0; i < inputMessage.Length; i++)
            {
                t1.Text += inputMessage[i].ToString();
            }
            return verifier.VerifySignature(input);
        }

        public byte[] signedWithRsa(byte[] input)
        {
            ISigner signer = SignerUtilities.GetSigner("SHA1withRSA");
            signer.Init(true, aliceKeyPair.Private);
            signer.BlockUpdate(input, 0, input.Length);
            byte[] signedData = signer.GenerateSignature();
            return signedData;
        }

        public bool verifyRsaSignedData(byte[] input, byte[] signature)
        {
            ISigner verifier = SignerUtilities.GetSigner("SHA1withRSA");
            verifier.Init(false, aliceKeyPair.Public);
            verifier.BlockUpdate(input, 0, input.Length);
            return verifier.VerifySignature(signature);
        }

    }
}

and here is steps of of running foo protocol. of course it doesn't have some of steps such as id sending but it's functionality is as true as Foo protocol

FooImplementing foo = new FooImplementing("Behzad");
var blindedMessage = foo.blindTheMessage(textBox2);
var userSignature = foo.signedWithRsa(blindedMessage);
if (foo.verifyRsaSignedData(blindedMessage, userSignature))
{
     var signedMessage = foo.blindSignature(blindedMessage);
     var unblindedMessage = foo.unblindeTheSignedData(signedMessage);
     MessageBox.Show(foo.verifyBlindSignature(unblindedMessage, textBox3).ToString());
 }

Notice That Text Boxes are for gathering result and isn't part of my program. Thank you all.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top