1
我使用C#中的RSACryptoServiceProvider
加密和解密數據,當我生成一個新的密鑰對時,我將私鑰返回給方法調用者,然後將公鑰保存到自制的PKI中(只是帶有keyBlob的字典和一個唯一的標識符)。RSA - 如何檢查公鑰信息?
我的問題是:因爲我需要存儲公鑰,所以我不想在PKI中意外存儲私鑰。但是,由於我還需要將私鑰寫入文件,因此我正在處理與ExportCspBlob
方法一起導出的字節數組。
我的問題:
如何確保通過檢查,我分析了我的StoreKey
方法byte[]
,它實際上是一個公共密鑰,它不包含私鑰信息?
爲了清楚起見,這裏是有關的代碼:
public static bool StoreKey(byte[] publicKeyParameters, string uniqueIdentifier)
{
bool success = false;
if (!keyCollection.ContainsKey(uniqueIdentifier))
{
if (!keyCollection.ContainsValue(publicKeyParameters))
{
keyCollection.Add(uniqueIdentifier, publicKeyParameters);
success = true;
}
}
return success;
}
而且GenerateKeys
方法:
public static byte[] GenerateKeys(string uniqueIdentifier)
{
byte[] privateKeyBlob;
using (var rsa = new RSACryptoServiceProvider(4096))
{
try
{
byte[] publicKey = rsa.ExportCspBlob(false);
privateKeyBlob = rsa.ExportCspBlob(true);
PublicKeyInfrastructure.StoreKey(publicKey, uniqueIdentifier);
}
finally
{
//// Clear the RSA key container, deleting generated keys.
rsa.PersistKeyInCsp = false;
}
}
return privateKeyBlob;
}
由於我工作的兩個不同的類,我想從初始化RSACryptoServiceProvider
棄權在我的PKI中,只需導入密鑰並進行檢查。這可能嗎?
太棒了,非常感謝! –
所以我查看了一些不同的生成密鑰,似乎我生成的公鑰共享數組中前20個索引的相同位模式。現在,當我想初始化一個字節數組並且得到新的字節[0x00,0x00,0x03 ...]時,我該如何寫入164位? 1x64?在此先感謝:) –
不完全確定你在問什麼。值得把這個問題作爲一個單獨的問題。 – Iridium