Home > Web Front-end > JS Tutorial > security.js+RSA makes encryption function

security.js+RSA makes encryption function

php中世界最好的语言
Release: 2018-06-07 09:49:43
Original
2466 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template