我正在尝试更多地了解 RSA 在 .NET 中的功能,并遇到了这篇有用的帖子,该帖子表明默认情况下密钥存储在 Windows 中: https ://stackoverflow.com/a/5845191/1181412
我的问题参考了下面的示例代码。假设意图是仅在应用程序会话的生命周期内生成一次性密钥。
问题 1:在下面的结构中,是否每次在类中的任何位置创建 RSACryptoServiceProvider 时都需要将 PersistKeyInCsp 标志设置为 false,即使它正在访问同一个 CspParameters 对象?
问题 2:在 CspParameters 对象上设置 CreateEphemeralKey 标志是否取代了在此示例中使用 PersistKeyInCsp 的需要?
Public Class RSACrypto
Private RSAKey As CspParameters
Public Sub New(KeySize As Integer)
MyBase.New()
RSAKey = New CspParameters
Using RSA As New RSACryptoServiceProvider(KeySize, RSAKey)
RSA.PersistKeyInCsp = False
End Using
End Sub
Public Function PublicKey() As Byte()
Using RSA As New RSACryptoServiceProvider(RSAKey)
RSA.PersistKeyInCsp = False
Return RSA.ExportCspBlob(False)
End Using
End Function
End Class