JQuery RSA加密(用户名和密码明文传输)
为解决用户名和密码明文传输的问题,经参考
实现以下解决步骤:
1、下载Jquery 的RSA加密解密 https://files.cnblogs.com/files/z5337/jsencrypt-master.zip?t=1658192133
2、下载 RSA 秘钥生成工具,可参考:https://blog.csdn.net/zhuiyunzhugang/article/details/108286632
3、使用命令生成公钥和私钥,
genrsa -out rsa_private_key.pem 1024
rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem
生成成功后,在 openssl.exe 同目录下会找到 rsa_private_key.pem 、rsa_public_key.pem 这两个文件
可以用记事本打开它,然后把内容复制到项目里面。
验证:我稍修改了一下 rsa加密的示例:
--- title: JSEncrypt Example layout: default --- <div class="container"> <script src="bin/jquery-1.12.4.min.js"></script> <script src="bin/jsencrypt.min.js"></script> <script type="text/javascript"> // Call this code when the page is done loading. $(function () { // Run a quick encryption/decryption when they click. $('#encrypt').click(function () { // Encrypt with the public key... var encrypt = new JSEncrypt(); encrypt.setPublicKey($('#pubkey').val()); var encrypted = encrypt.encrypt($('#inputTxt').val()); $('#encryptTxt').val(encrypted) }); // Run a quick encryption/decryption when they click. $('#decrypt').click(function () { // Decrypt with the private key... var decrypt = new JSEncrypt(); decrypt.setPrivateKey($('#privkey').val()); var uncrypted = decrypt.decrypt($('#inputTxt').val()); $('#decryptTxt').val(uncrypted) }); }); </script> <label for="privkey">Private Key</label><br/> <textarea id="privkey" rows="15" cols="65">-----BEGIN RSA PRIVATE KEY----- MIICXQIBAAKBgQDlOJu6TyygqxfWT7eLtGDwajtNFOb9I5XRb6khyfD1Yt3YiCgQ uku7JUXcVpt08DFSceCEX9unCuMcT72rAQlLpdZir876 -----END RSA PRIVATE KEY-----</textarea><br/> <label for="pubkey">Public Key</label><br/> <textarea id="pubkey" rows="15" cols="65">-----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlOJu6TyygqxfWT7eLtGDwajtN gwQco1KRMDSmXSMkDwIDAQAB -----END PUBLIC KEY-----</textarea><br/> <textarea id="inputTxt" name="input" type="text" rows=4 cols=70>This is a inputTxt!</textarea><br/> <label for="input">Text to encrypt:</label><br/> <textarea id="encryptTxt" name="input" type="text" rows=4 cols=70>This is a encrypt!</textarea> <input id="encrypt" type="button" value="encrypt"/><br/> <label for="input">Text to decrypt:</label><br/> <textarea id="decryptTxt" name="input" type="text" rows=4 cols=70>This is a decrypt!</textarea> <input id="decrypt" type="button" value="decrypt"/><br/> </div>
在此期间看到了 HslCommunication 这个类很强大