代码之家  ›  专栏  ›  技术社区  ›  Taylor Leese

C#-CryptographicException“坏哈希”

  •  4
  • Taylor Leese  · 技术社区  · 14 年前

    CreateSignature . 你知道是什么引起的吗?

    RSAPKCS1SignatureFormatter RSAFormatter = 
        new RSAPKCS1SignatureFormatter(new RSACryptoServiceProvider());
    RSAFormatter.SetHashAlgorithm("SHA256");
    byte[] signedHash = RSAFormatter.CreateSignature(myHash);
    
    2 回复  |  直到 14 年前
        1
  •  3
  •   Paul Sasik    14 年前

    MSDN :

    SHA256算法的哈希大小 是256位。

    尝试这样定义myHash:(这里只是一个丑陋的示例)

        // 256 bit hash size
        byte[] myHash = { 59,4,248,102,77,97,142,201,
              210,12,224,93,25,41,100,197,
              210,12,224,93,25,41,100,197,
              213,134,130,135, 213,134,130,135};
    

        2
  •  0
  •   Vladimir    13 年前
    byte[] bPlainText;
    bPlainText = Encoding.UTF8.GetBytes(PlainText);
    SHA256 sha256 = new SHA256Managed();
    bPlainText=sha256.ComputeHash(bPlainText);