0

誰かが次のコードを説明できますか..

そのreturnステートメントは何をしますか。

 public byte[] sign(string text)
 {
    string password = "1234";
    X509Certificate2 cert = new X509Certificate2("c:\\certificate.pfx", password);
    RSACryptoServiceProvider crypt = (RSACryptoServiceProvider)cert.PrivateKey;
    SHA1Managed sha1 = new SHA1Managed();
    UnicodeEncoding encoding = new UnicodeEncoding();
    byte[] data = encoding.GetBytes(text);
    byte[] hash = sha1.ComputeHash(data);
    return crypt.SignHash(hash, CryptoConfig.MapNameToOID("SHA1"));
}
4

2 に答える 2

1
    public byte[] sign(string text)
         {
//Password for the PFX certificate
            string password = "1234";
//Importing the PFX certificate that contains the private key which will be used for creating the digital signature
            X509Certificate2 cert = new X509Certificate2("c:\\certificate.pfx", password);
//declaring RSA cryptographic service provider
            RSACryptoServiceProvider crypt = (RSACryptoServiceProvider)cert.PrivateKey;
//cryptographic hash of type SHA1
            SHA1Managed sha1 = new SHA1Managed();
//encoding the data to be signed
            UnicodeEncoding encoding = new UnicodeEncoding();
            byte[] data = encoding.GetBytes(text);
//generate Hash
            byte[] hash = sha1.ComputeHash(data);
//sign Hash
            return crypt.SignHash(hash, CryptoConfig.MapNameToOID("SHA1"));
        }
于 2012-09-19T09:45:54.643 に答える
0

SignHash(byte[], string) メソッドは、証明書から読み取った秘密鍵に基づいて、最初の引数として渡すハッシュ値の署名を計算します。ここを参照してください:

RSACryptoServiceProvider.SignHash メソッド

この結果 (後で返される) は署名を含む byte[] になり、データと共に送信できるため、他の誰かが公開鍵を使用して署名を検証できます。

于 2012-09-18T12:35:24.303 に答える