For the extraction of public key private key, see http://www.cnblogs.com/dreamer-One/p/5621134.html for details
Additional online encryption and decryption tool Links: Http://tool.chacuo.net/cryptrsaprikey
--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)
The
Openresty uses a private key/public key for encryption/decryption/signing/verification.