用Bouncy Castle的C#版API产生公钥和私钥

本文介绍了如何使用Bouncy Castle的C#版本API来生成RSA公钥和私钥,并展示了如何利用这些密钥进行加解密操作。通过RsaKeyPairGenerator类初始化并设置参数,然后调用GenerateKeyPair()方法生成密钥对。测试代码中展示了使用公钥加密和私钥解密的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

开源API链接地址:The Legion of the Bouncy Castle

     Bouncy Castle,简称为BC,原本是java的一个开源JCE提供者,后来也提供了C#版本的API,我下载其编译好的DLL,在C#项目中直接引用,用其几个API,产生我指定位数的公钥和私钥(目前是1024位,但产生CA的密钥时,要2048位才能满足安全需求)。虽然开源很好很强大,但这个API就是文档很缺陷,C#的文档更是少得可怜,没办法,下载源代码慢慢看吧。。。

 

     在接下来的几篇关于CA文章中,大体按下面链接网址的思路去整理,不过整理出来的是C#版本的实现,基本目标架设一个CA,产生用户使用的数字证书。网页链接:bouncycastle 产生证书

 

     产生密钥,主要是用RsaKeyPairGenerator,根据参数RsaKeyGenerationParameters,产生一个密钥对,再分离出公钥和私钥,再用公钥和私钥进行加解密。

 

RsaKeyPairGenerator的类,类中的其他类自行加载“BouncyCastle.Crypto.dll”到VS中自行查看

■Generation and parsing of PKCS#12 files. ■X.509: Generators and parsers for V1 and V3 certificates, V2 CRLs and attribute certificates. ■PBE algorithms supported by PBEUtil: PBEwithMD2andDES-CBC, PBEwithMD2andRC2-CBC, PBEwithMD5andDES-CBC, PBEwithMD5andRC2-CBC, PBEwithSHA1andDES-CBC, PBEwithSHA1andRC2-CBC, PBEwithSHA-1and128bitRC4, PBEwithSHA-1and40bitRC4, PBEwithSHA-1and3-keyDESEDE-CBC, PBEwithSHA-1and2-keyDESEDE-CBC, PBEwithSHA-1and128bitRC2-CBC, PBEwithSHA-1and40bitRC2-CBC, PBEwithHmacSHA-1, PBEwithHmacSHA-224, PBEwithHmacSHA-256, PBEwithHmacRIPEMD128, PBEwithHmacRIPEMD160, and PBEwithHmacRIPEMD256. ■Signature algorithms supported by SignerUtilities: MD2withRSA, MD4withRSA, MD5withRSA, RIPEMD128withRSA, RIPEMD160withRSA, RIPEMD256withRSA, SHA-1withRSA, SHA-224withRSA, SHA-256withRSAandMGF1, SHA-384withRSAandMGF1, SHA-512withRSAandMGF1, SHA-1withDSA, and SHA-1withECDSA. ■Symmetric key algorithms: AES, Blowfish, Camellia, CAST5, CAST6, DESede, DES, GOST28147, HC-128, HC-256, IDEA, NaccacheStern, RC2, RC4, RC5-32, RC5-64, RC6, Rijndael, Serpent, Skipjack, TEA/XTEA, Twofish, and VMPC. ■Symmetric key modes: CBC, CFB, CTS, GOFB, OFB, OpenPGPCFB, and SIC (or CTR). ■Symmetric key paddings: ISO10126d2, ISO7816d4, PKCS#5/7, TBC, X.923, and Zero Byte. ■Asymmetric key algorithms: RSA (with blinding), ElGamal, DSA, ECDSA. ■Asymmetric key paddings/encodings: ISO9796d1, OAEP, and PKCS#1. ■Digests: GOST3411, MD2, MD4, MD5, RIPEMD128, RIPEMD160, RIPEMD256, RIPEMD320, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, Tiger, and Whirlpool. ■Signer mechanisms: DSA, ECDSA, ECGOST3410, GOST3410, ISO9796d2, PSS, RSA. ■Key Agreement: Diffie-Hellman and EC-DH. ■Macs: CBCBlockCipher, CFBBlockCipher, GOST28147, HMac, and ISO9797 Alg. 3. ■PBE generators: PKCS#12, and PKCS#5 - schemes 1 and 2. ■OpenPGP (RFC 4880) ■Cryptographic Message Syntax (CMS, RFC 3852), including streaming API. ■Online Certificate Status Protocol (OCSP, RFC 2560). ■Time Stamp Protocol (TSP, RFC 3161). ■TLS/SSL Client with support for client side authentication.
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值