security.js实现的RSA加密功能示例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

security.js实现的RSA加密功能示例

南乔几经秋   2020-05-16 我要评论

本文实例讲述了security.js实现的RSA加密功能。分享给大家供大家参考,具体如下:

在项目中遇到要对用户输入的密码进行RSA加密的需求,总结一下实现过程:

<html>
<head>
<meta charset="utf-8" />
<title>www.qb5200.com JS rsa加密</title>
</head>
<body>
  <div>
   <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="加密后"/>
  </div>
 <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>

这里的exponent参数和modulus参数讲道理是要从后台获取的,这里写做输入框获取是作测试用。

security.js点击此处本站下载

PS:关于加密解密感兴趣的朋友还可以参考本站在线工具:

在线RSA加密/解密工具:
http://tools.softyun.net/password/rsa_encode

文字在线加密解密工具(包含AES、DES、RC4等):
http://tools.softyun.net/password/txt_encode

在线编码转换工具(utf-8/utf-32/Punycode/Base64):
http://tools.softyun.net/transcodinghttps://img.qb5200.com/download-x/decode_encode_tool

BASE64编码解码工具:
http://tools.softyun.net/transcoding/base64

在线MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160加密工具:
http://tools.softyun.net/password/hash_md5_sha

在线sha1/sha224/sha256/sha384/sha512加密工具:
http://tools.softyun.net/password/sha_encode

希望本文所述对大家JavaScript程序设计有所帮助。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们