JQuery + C # implement parameters RSA encryption transfer function [attached jsencrypt.js download]

This example describes the jQuery + C # implementation parameter RSA encryption transmission function. Share to everyone for reference, specifically:

Parameter passed + number processing, turn + to space in transmission, after no processing The end is wrong.

     login      $ (Function () {var Encrypt = new jsencrypt (); Encrypt.SetPublicKey ($ ("# tra"). Val ()); var data = encrypt.encrypt ("123456789" Alert (DATA); $ ("# btn"). Click (Function () {$ .ajax ({URL: '@ Url.Action ("Login")', Data: "PWD =" + Encodeuri (DATA ) .Replace (/ \ + / g, '% 2b'), // + number processing: Because the data is transmitted on the network, the non-alphanumeric characters will be replaced with a percentage (%) and then two ten Six times, while Base64 encoding is transferred to the backend, + will turn into spaces, so replace it back. Replace back TYPE: 'POST', SUCCESS: Function (MSG) {Alert (msg); });});});       MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCa4KHNwDX44gGmmIAtRu4gjVYtGWZzcm4t + 1wjUD4dn7fMLPvuK7ai4UrfDeEJE1RPwudJw + lJ6crql8wSIg7 / DbTl G3ihsCT6dT9H5B9OoeR7K9VWUesaW / iyVL6HXiYOANabW14pvJATDmdq91Tfgp6P SQyvdfiRdV4r07crpQIDAQAB 
Processing] Note that a + sign
2, backend code

Public class indexController: controller {public actionResult login () {returnirew ();} [httppost] public ActionResult login (string pwd) {// key format to generate formatted pkcs # 1 instead pkcs # 8 format string privateKey = @ “MIICWwIBAAKBgQCa4KHNwDX44gGmmIAtRu4gjVYtGWZzcm4t + 1wjUD4dn7fMLPvuK7ai4UrfDeEJE1RPwudJw + lJ6crql8wSIg7 / DbTlG3ihsCT6dT9H5B9OoeR7K9VWUesaW / iyVL6HXiYOANabW14pvJATDmdq91Tfgp6PSQyvdfiRdV4r07crpQIDAQABAoGABb + 3gdb + qeG0b1CogVsT / 7 // UOaTzPk / FGneKQQTf4SsN + H7lVhTYTG9ARFCJyoWg8IXqmn2ljhywHPTWWD2RCZIn2sYT1sVkGb70EgHGQLBraFHElmw + DsVJ + nDfBCfMrJ1TYXlwigjRkaueaoGgG8LdR8XD + Xs5LersPLjZgECQQCguSB7C4wF6oSwEDmwNF8ffT5cQc1U2OIq6NBG8rafrjb7LsjhOd03pmY7i4LbW3Vvq4AhQpJEdF1Cvd + Sk / BBAkEA9rBhqnyumV09zFEomSX3zZu + bdhTzM4bJDfEa95swp1gANCVvF / tDCnlBf51EhCWdeGSpARPUkQnXrYfFUDiZQJAAZEshuaa6 + fYeVr / JP + tucHf3MhrdxtSQTbZ6QcuzqnFMXfIT6HfzU4bCxOWKAthPsB + VFSw1mgIDMGLL4OvwQJAJlVyV9PYLezXVZCnBmVoBINXLCqZmxHMFey0kS6XKAbcjEPdgNBHPcSk2jGYb540Q00yRFqHGPmORKF4Yw0aIQJAd5JRtD3z2MgP / vPoKHJNHqY8bboVcmwqVAm6xCZoTCZzjNV1Cnsdf4wBV3LCDzYBy + xR4qYNUy5CFXN + 8WzzAA == “; try {RSACryptoServiceProvider rsaCryptoServiceProvider = CreatersaproviderFromPrivateKey (PrivateKey); // Put +, replace it backByte [] res = rsacryptoserviceProvider.Decrypt (Convert.FromBase64String (pwd.replace, “+”)), false; returnization.utf8.getstring (res));} catch (Exception Exception) {} return Content ( “”);} private RSACryptoServiceProvider CreateRsaProviderFromPrivateKey (string privateKey) {var privateKeyBits = System.Convert.FromBase64String (privateKey); var RSA = new RSACryptoServiceProvider (); var RSAparams = new RSAParameters (); using (BinaryReader binr = new BinaryReader (new MemoryStream (privateKeyBits))) {byte bt = 0; ushort twobytes = 0; twobytes = binr.ReadUInt16 (); if (twobytes == 0x8130) binr.ReadByte (); else if (twobytes == 0x8230 ) BINR.REAdInt16 (); else throw new Exception ( “Unexpected value read binr.ReadUInt16 ()”); twobytes = binr.ReadUInt16 (); if (! twobytes = 0x0102) throw new Exception ( “Unexpected version”); bt = binr. ReadByte (); if (! bt = 0x00) throw new Exception ( “Unexpected value read binr.ReadByte ()”); RSAparams.Modulus = binr.ReadBytes (GetIntegerSize (binr)); RSAparams.Exponent = binr.ReadBytes (GetIntegerSize (binr)); rsaparams.d = binr.readBytes (GetIntegersize (binr)); rsaparams.p = binr.readbytes (BINR)); rsaparams.q = binr.readbytes (GetIntegersize (binr)); rsaparams.dp = Binr.Readbytes (GetIntegersize (binr)); rsaparams.dq = binr.readBytes (GetIntegersize (binr)); rsaparams.inverseQ = binr.ReadBytes (GetIntegerSize (binr));} RSA.ImportParameters (RSAparams); return RSA;} private int GetIntegerSize (BinaryReader binr) {byte bt = 0; byte lowbyte = 0x00; byte highbyte = 0x00; int count = 0; bt = binr.readByte (); if (bt! = 0x02) Return 0; bt = binr.readbyte (); if (bt == 0x81) count = binr.readbyte (); else if (bt == 0x82 ) {highbyte = binr.readbyte (); lowbyte = binr.readbyte (); byte [] modint = {lowbyte, highbyte, 0x00, 0x00}; count = bitconverter.toint32 (MODINT, 0);} else {count = BT ;} while (binr.readbyte () == 0x00) {count – = 1;} biNr.basestream.seek; return count;}}

 Close:  jsencrypt.min.js Click this  
This site downloads
.

PS: Friends who are interested in encryption can also refer to this site online tool: MD5 online encryption tool: HTTP : //Tools.jb51.net/password/createmd5password

Thunder, Express, Cyclone URL encryption / decryption tool:

http://tools.jb51.net/password/ URLRETHUNDER


Infrared / hash algorithm encryption tool:

http://tools.jb51.net/password/hash_encrypt


Online MD5 / HASH / SHA-1 / SHA-2 / SHA-256 / SHA-512 / SHA-3 / RIPEMD-160 encryption tool:

http://tools.jb51.net/password/hash_md5_sha


Online SHA1 / SHA224 / SHA256 / SHA384 / SHA512 Encryption Tools:

http://tools.jb51.net/password/sha_encode

More about jQuery Readers interested in content to view this topic: “jQuery common plug-in and usage summary”, “jQuery extension skill summary”, “jQuery switching special effects and skill summary”, “jQuery traversAlgorithm and Skill Summary

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment