[英]OAEP with SHA1 and MGF1 with BouncyCastle?
我正在嘗試在 .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 之類的方法。
它在他的單元測試(第 302 行)中使用名為 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.