Golang RSA Public Private key PEM file generation

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. func Main () {
   //rsa  key file generation
 genrsakey(1024x768)
}

RSA public Key generation
Funcgenrsakey (bitsint) error  {
  //  generate private key file
 privatekey,err: =RSA. GenerateKey(rand. Reader,bits)
  if Err! =Nil {
  returnerr
    }
 derstream: =x509. Marshalpkcs1privatekey(privatekey)
 block: =&Pem. Block{
 Type: "RSA PRIVATE KEY"   ,
 Bytes:derstream,
    }
 file,err: =os. Create("Private.pem")
  if Err! =Nil {
  returnerr
    }
 err=Pem. Encode(file,block)
  if Err! =Nil {
  returnerr
    }
  //  generate public key file
 publickey: =&privatekey. PublicKey
 Derpkix,err: =x509. Marshalpkixpublickey(publickey)
  if Err! =Nil {
  returnerr
    }
 block=&Pem. Block{
 Type: "public KEY",  
 Bytes:derpkix,
    }
 file,err=os. Create("Public.pem")
  if Err! =Nil {
  returnerr
    }
 err=Pem. Encode(file,block)
  if Err! =Nil {
  returnerr
    }
  returnNil
}-----BEGIN RSA PRIVATE KEY-----
miicwwibaakbgqdvuvoh3ydbxhag7kfk5aaopkkgx2plofjni/uzgz/obegiy38p
+frdl42ehjcan6fistzgupzujxwgswqwvza8tx964r3cif6xt60gybdohyrfmklu
Ki3ba560dkhgcw+0lhn/qis12ixnesql508qvo37twwl86i+8hy40xyu+widaqab
An9evyogt3cl418vr0oordbkcnwpgdmwvp2qtx9xo5er0lh5yfg0g6ouhgj+kd+3
Bsii1ofairq4nvk/06g44itno4zm3vdp5kt1cdgdwrydt8fpg0hdsscfxlxf1r6q
Zinw2/bt0sxh70egqqxy7pm+ngucusfrjhksmcnyxybzakea/xxntdqzhgbb5c4b
huqnwzqubsobaw25uoem/yqj9qeircoy0niw2hrjfdgnniv6uoeiphvj/bvn735o
5g9nnqjbanz5vbjwluvzob6h5vwcu5bqf6r3+5pvome8axb+arwl6n805jjttl8j
Gi5rkgll3tf6vdjdol05cvahcyp5aw8cqgb/fiw1lobhvdsnzc/kgddt942o2zi3
Ematqnksp0vh7nxgas+mp85yyed0jwuy/0iuwhunbgoulnmdf6ifcxkcqqcxorwa
5j2vz1pazwoktuq6szggxjb7gllseccceywumglkogdk+u1u3xhqcrhyhy4iehka
E8gqltqzeuqldbbvakea7pm6amxzrdgl+w6fzsr18or7fliinorc0dmerrr11hzs
6nxrvd66itxaqts01vpgivpdrppsoosa7ccwiuvbva==
-----ENDRSAPRIVATEKEY-----


-----BEGIN Public KEY-----
migfma0gcsqgsib3dqebaquaa4gnadcbiqkbgqdvuvoh3ydbxhag7kfk5aaopkkg
x2plofjni/uzgz/obegiy38p+frdl42ehjcan6fistzgupzujxwgswqwvza8tx96
4r3cif6xt60gybdohyrfmkluki3ba560dkhgcw+0lhn/qis12ixnesql508qvo37
Twwl86i+8hy40xyu+widaqab
-----ENDpublicKEY-----


Related Article

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.