Master_T
Master_T

Reputation: 7913

Encrypting a private key with BouncyCastle

I'm using the .NET version of BouncyCastle, and I have to save a private RSA key to file, obviously encrypted with a password for security reasons.

What I'm trying right now is this:

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
)

But BouncyCastle is thwrowing a NullReferenceException on the last instruction. Since the method is totally undocumented >:( I wonder if any of you know how to use it correctly...

(none of my parameters are NULL by the way, already checked that)

Upvotes: 5

Views: 1584

Answers (1)

President James K. Polk
President James K. Polk

Reputation: 41967

That particular PBE algorithm won't work. Try this instead: "PBEwithSHA-1and3-keyDESEDE-CBC"

Upvotes: 3

Related Questions