海蘭大家一個消息,哈希並簽署與RSA算法中的C#緊湊框架
我嘗試登錄與RSA算法的一個消息,我的工作,以緊湊Framwork這是我的代碼:
private void Signer_Click(object sender, EventArgs e)
{
///cle de string ver byte[]
string clePriveeFile = @"\Program Files\PrivateKey.pem";
StreamReader reader = new StreamReader(clePriveeFile);
string contenuKeyPrivate = reader.ReadToEnd();
byte[] keyByte = Certification.DecodeOpenSSLPrivateKey(contenuKeyPrivate);
string Data = "Salut tout le monde";
byte[] DataBytes = System.Text.Encoding.UTF8.GetBytes(Data);//.UTF7.GetBytes(Data);
//Hasher le message
SHA1Managed sha1 = new SHA1Managed();
byte[] hash = sha1.ComputeHash(DataBytes);
string hach = Convert.ToBase64String(hash);
RSACryptoServiceProvider Rsa = Certification.DecodeRSAPrivateKey(keyByte);
byte[] sign = Rsa.SignHash(hash, CryptoConfig.MapNameToOID("SHA1"));
string resultat = Convert.ToBase64String(sign);
this.label1.Text = this.resultat;
}
與 'DecodeOpenSSLPrivateKey' 和 'DecodeRSAPrivateKey' 這是薩姆斯功能使用這裏:http://www.jensign.com/opensslkey/index.html
我的散列的結果,我獲得:哈希= 「I4t474liO6H + p8SeDsoIkxmi8b0 =」
如果我用openSSL命令做同樣的事情:$ echo「Salut tout le monde」| openssl dgst -sha1 | OpenSSL的ENC -base64
我得到這樣的: 「NjFlOWI4Y2NjN2U2MzFkNTQwNTRmZjE1ZGUyYzk2MDczYTM2ZjRjZAo =」
同我簽結果,使用這個命令:
$回聲 「薩呂兜售世界報」 | openssl dgst -sha1 -sign PrivateKey.pem | OpenSSL的ENC -base64
我有這樣的簽名: 「V6c6XNK7O8 + IKKuGTGENdZwoWxhQLIEFHW7XSdoXzMAp1gLu8B5UxXi0lr6JhVDW6SI8p8PtlT + fxEoafY + ZCigIq4xW6e32f6hxYWeYi7silh44I1m7LF7JYR1lfcegnO0Cw + YPqLPRrZUbdcrvMo1ijUGH3SuK + iot2lait9s =」
與我的代碼獲得此:
結果=「YlbnppFDP5ejdYOPoUI/1W6i + ClrKrxbIdA24IqllGDRWGBrWLtGwlfNkh4 + B + gzcrX8HI7PkNP1Pq2ud1jE4EhfUVjBkZJwXj/ZYI3fPF41oiIMdF63lZiR/SEHQ5rMTbdsfQtkkBmFTr8udCJNnmnSimRQ458nZvIsYOUW6j4 =」
我無法找到我的錯誤:(有人可以幫我嗎?
我想你的方法,但我不跟我的代碼獲得相同的價值,也許是因爲我有一些錯誤的,我用C#代碼?現在在OpenSSL中使用「echo」Salut tout le monde \ n「| openssl dgst -sha1」我得到這個:d12bb896839290faf65f279e3fe179b339eeecca我也試着回顯「Salut tout le monde \ n」| openssl dgst -sha1 -binary | openssl enc -base64,但我沒有與我的代碼在c#中的結果相同 – ririrourou 2010-12-02 14:02:43