简体   繁体   中英

Encrypt and store a private+public key with Bouncy Castle

I created a AsymmetricCipherKeyPair with the ECKeyPairGenerator and want to store the private and public key.

I found the following classes and methods to archive this:

PrivateKeyFactory.EncryptKey(...)  
EncryptedPrivateKeyInfoFactory.CreateEncryptedPrivateKeyInfo(...)

What is the recommend API to use?

But what algorithm should be used? I tested "BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes128_cbc" and got an exception "attempt to use non-PBE algorithm with PBE EncryptedPrivateKeyInfo generation"

I also tested "PBEWITHSHAAND128BITAES-CBC-BC" and it took ages to complete.

So is there a recommend way to store (and read in later) a private and public key with Bouncy Castle C# ?

You were on the right track, those are the right classes. However BC had bugs in the bindings for the AES-based PBE encryption algorithms, which I've only just now fixed in CVS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM