C # Security API

Source: Internet
Author: User

Bouncycastle

The official website address is: http://www.bouncycastle.org/csharp/.

http://blog.csdn.net/popozhu/article/details/5812662

Http://www.xuebuyuan.com/301023.html

Read key from Pem file
New Pemreader (new StreamReader ("files/pubkey.pem"= ( Asymmetrickeyparameter) R.readobject ();
New Pemreader (new StreamReader ("files/prvkey.pem"= ( Asymmetrickeyparameter) R.readobject ();

Load the PFX certificate library, read the certificate, get the secret key
FileStream ms =NewFileStream ("STORE.P12", Openmode.open); Pkcs12store Store=NewPkcs12storebuilder (). Build (); store. Load (MS,"123456". ToCharArray ());//get first aliasIEnumerator Itor =store. Aliases.getenumerator (); Itor. MoveNext ();stringAlins =Itor. Current.tostring (); Asymmetrickeyparameter Prvkey=NULL; Asymmetrickeyparameter PubKey=NULL;if(Sotre. Iskeyentry (alins)) Prvkey=store. GetKey (Alins). Key;cert=store. GetCertificate (Alins). Certificate;pubkey=cert. Getpublickey ();

Encrypt, decrypt
Asymmetrickeyparameter prvkey=...; Asymmetrickeyparameter PubKey=...;//Public Key Cryptographystringorigin="abcd1234";byte[] originbytes=Encoding.Default.getBytes (origin); Ibufferedcipher c= Cipherutilities.getcipher ("rsa/ecb/pkcs1padding"); C.init (true, PubKey);byte[] Encrybytes =C.dofinal (origin);stringEncrystr=Encoding.Default.GetString (encrybytes);//private Key DecryptionIbufferedcipher C = Cipherutilities.getcipher ("rsa/ecb/pkcs1padding"); C.init (false, Prvkey);byte[] recoverbytes=c.dofinal (encrybytes);stringRecover=encoding.default.getstring (recoverbytes);

Signing, verifying

Generate and export keys, certificates, libraries

C # Security API

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.