我正在使用BouncyCastle的.NET版本,需要将一个私有RSA密钥保存到文件中,并且为了安全原因,需要加密该密钥并设置密码。
我目前尝试的方法如下:
Dim rand As New SecureRandom
Dim arr As Byte() = New Byte(7) {}
rand.NextBytes(arr)
Dim privateKeyInfo As EncryptedPrivateKeyInfo = EncryptedPrivateKeyInfoFactory.CreateEncryptedPrivateKeyInfo(
"PBEwithHmacSHA-256",
Repository.Password.ToCharArray,
arr,
1,
data.BouncyCastlePrivateKey
)
但是BouncyCastle在最后一条指令上抛出了NullReferenceException异常。由于该方法完全没有记录,我想知道你们中是否有人知道如何正确使用它...
顺便说一下,我的参数都不是NULL,已经检查过了。