Home > Article > Web Front-end > security.js+RSA makes encryption function
This time I will bring you security.js RSA encryption function, what are the precautions, the following is a practical case, let's take a look.
In the project, I encountered the need to encrypt the password entered by the user with RSA. Let me summarize the implementation process:
<html> <head> <meta charset="utf-8" /> <title>JS rsa加密</title> </head> <body> <p> <input type="text" id="pwd" placeholder="请输入密码"/><br /> <input type="text" id="key1" placeholder="请输入modulus参数"/><br /> <input type="text" id="key2" placeholder="请输入exponent参数"/> <button id="btn">加密</button><br /> <input type="text" id="pwd1" placeholder="加密后"/> </p> <script type="text/javascript" src="../RSA加密/security.js"> //引入security.js文件 </script> <script> var btn = document.getElementById('btn'); btn.onclick = function(){ var pwd = document.getElementById('pwd').value; var modulus = document.getElementById('key1').value; var exponent = document.getElementById('key2').value; //加密 var key = RSAUtils.getKeyPair(exponent, "", modulus); var apwd = RSAUtils.encryptedString(key, pwd); //加密后的密码; document.getElementById('pwd1').value = apwd; } </script> </body> </html>
The exponent parameters and modulus parameters here should be obtained from the background. , written here as input box acquisition is for testing purposes.
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
vue makes a searchable drop-down box
String array deduplication practical case analysis
The above is the detailed content of security.js+RSA makes encryption function. For more information, please follow other related articles on the PHP Chinese website!