1
實施電子商務表決系統,我的工作基礎上Foo92協議的E投票系統。我是Bouncy Castle圖書館的新手。但是我必須說明這個基於盲簽名和RSA算法的系統。這個計劃(FOO92)有一個圖表,我已經爲你上傳了。我想知道如何盲目簽署並在Bouncy Castle圖書館進行驗證。請幫我解決我的問題。 謝謝大家。 使用充氣城堡
請注意*運算符是致盲運算符。和/運營商是unblinding運營商。
實施電子商務表決系統,我的工作基礎上Foo92協議的E投票系統。我是Bouncy Castle圖書館的新手。但是我必須說明這個基於盲簽名和RSA算法的系統。這個計劃(FOO92)有一個圖表,我已經爲你上傳了。我想知道如何盲目簽署並在Bouncy Castle圖書館進行驗證。請幫我解決我的問題。 謝謝大家。 使用充氣城堡
請注意*運算符是致盲運算符。和/運營商是unblinding運營商。
最後,我已經寫了充氣城堡守則FOO92電子投票協議。 下面是類:
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);
}
}
}
這裏是運行FOO協議的步驟。當然它沒有一些步驟,諸如ID發送,但它的功能是作爲真正爲Foo協議
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());
}
通知,文本框是收集結果,不是我的計劃的一部分。 謝謝大家。
感謝您與我們分享答案,Behzad。如果你真的在17個小時內創建和測試過,我想你沒問題:) –
歡迎你的朋友。 –