与充气城堡签约时的 Pkcs1 填充

Pkcs1 padding while signing with bouncy castle

我有以下 c# Bouncy Castle 代码,可以使用 RSA/SHA512 在 C# 中对一些数据进行签名。谁能告诉我如何在此过程中应用 Pkcs1 填充?

using (var txtreader = new StringReader(File.ReadAllText(_certificatePath)))
{
    var keyPair = (AsymmetricCipherKeyPair)new PemReader(txtreader).ReadObject();

    var key = keyPair.Private as RsaPrivateCrtKeyParameters;
    ISigner sig = SignerUtilities.GetSigner("SHA512withRSA");
    sig.Init(true, key);

    sig.BlockUpdate(requestToSign, 0, requestToSign.Length);
    byte[] signature = sig.GenerateSignature();
}

PKCS#1 实际上是唯一用于 RSA-SHA512 签名的填充算法。

勾选RFC 4051:

2.3.4. RSA-SHA512

This implies the PKCS#1 v1.5 padding algorithm [RFC3447] as described in section 2.3.1, but with the ASN.1 BER SHA-512 algorithm designator prefix.

您也可以查看 BouncyCastle source codeRsaDigestSigner 在没有任何条件或配置的情况下创建 Pkcs1Encoding 的实例:

private readonly IAsymmetricBlockCipher rsaEngine = new Pkcs1Encoding(new RsaBlindedEngine());

您还可以在调试下检查使用的实现:

所以回答问题:

Can any tell me how I can also apply Pkcs1 padding in this process?

不应采取任何其他措施。 Pkcs1 是唯一可能用于 RSA-SHA512 签名的填充算法。