The openresty uses a private key/public key to encrypt/decrypt/sign/verify.

Source: Internet
Author: User
Tags begin rsa private key

For the extraction of public key private key, see for details
Additional online encryption and decryption tool Links: Http://
--Public key
Local Rsa_public_key=[[-----BEGIN RSA Public KEY-----migjaogbaj9yqfctlhnmtyncezmfy7yb7xwazrinxup1zl51517rhjq8w0wvwnt+Mckwrzisa1siqpglhiydb2rjkc1ccnrvnfj7xxokciihkistikxzdfeaqrm0bu80Bsjgjj6yukzinuaacpoao8v+qforlxlsay72my7ipvnjqbd1aopvagmbaae=-----END RSA Public KEY----- ]]
--Private keyLocal Rsa_priv_key=[[-----BEGIN RSA PRIVATE KEY-----Miicxaibaakbgqcfwkhqk5yz5k2dqnszh8u8m+8cam0yp17qdwzedede64savftmFcdbfpncsec4ranuikjxpyysg29kssnnxaja1tx4+8ctigiiozcleycl8w33gkq5Tg1pnauo4i4+mfcmyp1aaaj6gqpl/kbaezv5bamu9pmo4qvzyagxdqdj1qidaqabAogbajega3lrfvhkplp6vptm+p2c3cipcppvgxkncd42f1xjusnthkuhxh6xf4u07hc27exqpkjbozo99g89t3nccmczpoccz4an0lckv9ovzqz3avz6ayreseswlpqyAgmjevuve/cdwkhjavicbwc4rni3obrhxmy2h3smo0gkx3d5akeayvtrrbxdcqewS4oi2pnalhyli1apdi/wn76onkw/dq36spcqmltzgmdfxviuhh19ysv5id8addbe/b72yqlcuwjbamj97vfpinowm2sawm3tw60fbjoxxuwlc6ltefqamfcv94zt/vpgNv93jkf9dlqc/cwhbjzbvtytlzpevxyl8q8cqhiakhkcopr2475f61fxj1cobzyoSuazeswhzpjlndwkm2i9d1ix5vdtvaj3mf/cnlvtwbchlcxjsvabdi1uruccqamnInq6/mcopw6ac3x0uc3jeigwzktoxmsi/jawmdw/5zfioo06bui+iwrd4vrsogh9G2ipdgwic0uuf+ddm6kcqf2/ubl6mzkdc4rveff3vjh7escfmfssq/evez637n062pzsvvb4xq6gt9vwogvnsn5r/k6abt+rmeww57jo7pg=-----END RSA PRIVATE KEY----- ]]--Public Key CryptographyLocal Resty_rsa=Require"Resty.rsa"Local pub, err= Resty_rsa:New ({Public_key= Rsa_public_key})IfNot pubThen Ngx.Say"New RSA ERR:", err)ReturnEndLocal encrypted, err= Pub:Encrypt"Hello")IfNot encryptedThen Ngx.Say"Failed to encrypt:", err)ReturnEnd Ngx.Say"Encrypted length:",#encrypted)--private key decryptionLocal Priv, err= Resty_rsa:New ({Private_key= Rsa_priv_key})IfNot PrivThen Ngx.Say"New RSA ERR:", err)ReturnEndLocal decrypted= Priv:Decrypt (encrypted) Ngx.Say (decrypted=="Hello")--private key signatureLocal algorithm="SHA"Local Priv, err= Resty_rsa:New ({Private_key= Rsa_priv_key, algorithm= algorithm})IfNot PrivThen Ngx.Say"New RSA ERR:", err)ReturnEndLocal STR="Hello"Local SIG, Err= Priv:Sign (str)IfNot sigThen Ngx.Say"Failed to sign:", err)ReturnEnd Ngx.Say"Sig Length:",#sig)--public key verificationlocal pub, err = resty_rsa:new ({Public_key = rsa_public_key, Algorithm = Algorithm}) if not pub then ngx. Say ( "new RSA err: ", err) return Span class= "Pl-k" >end local verify, Err = pub:verify (str, SIG) if not verify then ngx. Say ( "Verify err: return Span class= "Pl-k" >end ngx. say (verify)


Openresty uses a private key/public key for encryption/decryption/signing/verification.

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: 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.