带有SHA1的OAEP和带有BouncyCastle的MGF1?

时间:2019-08-10 13:26:02

标签: c# .net-2.0

我正在尝试在.NET Framework 2.0上使用BouncyCastle对c#进行RSA/ECB/OAEPWithSHA1AndMGF1Padding

我已经想到了:

IAsymmetricBlockCipher engine = new OaepEncoding(new RsaEngine(), new Sha1Digest(), new Sha1Digest(), null);
using (var stream = new StreamReader(publicKey))
{
    var pemReader = new PemReader(stream);
    var pemObj = pemReader.ReadObject();
    var keyPair = (RsaKeyParameters)pemObj;
    engine.Init(true, keyPair);
}
var message = "test";
var data = Encoding.UTF8.GetBytes(message);
var encrypted = engine.ProcessBlock(data, 0, data.Length);

我的问题是,这等同于使用BouncyCastle和c#的RSA/ECB/OAEPWithSHA1AndMGF1Padding还是正确的方法?

我对这里的参数也有疑问:

IAsymmetricBlockCipher engine = new OaepEncoding(new RsaEngine(), new Sha1Digest(), new Sha1Digest(), null);

我找不到将第二个Sha1Digest定义为MGF1之类的方法。

1 个答案:

答案 0 :(得分:1)

看看DataFrame.set_index

它在其Peter Dettman's GIT中使用名为CipherUtilities的通用类中的IBufferedCipher来解决此问题,他是这样做的(第302行):

c = CipherUtilities.GetCipher("RSA/NONE/OAEPWithSHA1AndMGF1Padding");
c.Init(false, privKey);
outBytes = c.DoFinal(outBytes);
if (!AreEqual(outBytes, input))
{
    Fail("OAEP test failed on decrypt expected " + Hex.ToHexString(input) + " got " + Hex.ToHexString(outBytes));
}

请注意,c是IBufferedCipher