security.js實現(xiàn)的RSA加密功能示例
本文實例講述了security.js實現(xiàn)的RSA加密功能。分享給大家供大家參考,具體如下:
在項目中遇到要對用戶輸入的密碼進行RSA加密的需求,總結(jié)一下實現(xiàn)過程:
<html> <head> <meta charset="utf-8" /> <title>www.dbjr.com.cn JS rsa加密</title> </head> <body> <div> <input type="text" id="pwd" placeholder="請輸入密碼"/><br /> <input type="text" id="key1" placeholder="請輸入modulus參數(shù)"/><br /> <input type="text" id="key2" placeholder="請輸入exponent參數(shù)"/> <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參數(shù)和modulus參數(shù)講道理是要從后臺獲取的,這里寫做輸入框獲取是作測試用。
security.js點擊此處本站下載。
PS:關(guān)于加密解密感興趣的朋友還可以參考本站在線工具:
在線RSA加密/解密工具:
http://tools.jb51.net/password/rsa_encode
文字在線加密解密工具(包含AES、DES、RC4等):
http://tools.jb51.net/password/txt_encode
在線編碼轉(zhuǎn)換工具(utf-8/utf-32/Punycode/Base64):
http://tools.jb51.net/transcoding/decode_encode_tool
BASE64編碼解碼工具:
http://tools.jb51.net/transcoding/base64
在線MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160加密工具:
http://tools.jb51.net/password/hash_md5_sha
在線sha1/sha224/sha256/sha384/sha512加密工具:
http://tools.jb51.net/password/sha_encode
更多關(guān)于JavaScript相關(guān)內(nèi)容可查看本站專題:《JavaScript加密解密技巧匯總》、《JavaScript查找算法技巧總結(jié)》、《JavaScript錯誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學運算用法總結(jié)》
希望本文所述對大家JavaScript程序設(shè)計有所幫助。
- 原生js的RSA和AES加密解密算法
- PHP+JS+rsa數(shù)據(jù)加密傳輸實現(xiàn)代碼
- jQuery+C#實現(xiàn)參數(shù)RSA加密傳輸功能【附j(luò)sencrypt.js下載】
- NodeJS加密解密及node-rsa加密解密用法詳解
- PHP rsa加密解密使用方法
- php rsa加密解密使用詳解
- php基于openssl的rsa加密解密示例
- php rsa 加密,解密,簽名,驗簽詳解
- PHP的RSA加密解密方法以及開發(fā)接口使用
- PHP實現(xiàn)RSA加解密算法示例(生成密鑰位數(shù)為1024位的方法)
- 基于PHP RSA密文過長加密解密 越過1024的解決方法
- RSA實現(xiàn)JS前端加密與PHP后端解密功能示例
相關(guān)文章
JS面試必備之手寫instanceof,深拷貝,節(jié)流和防抖
JavaScript如何實現(xiàn)手寫instanceof、深拷貝、節(jié)流、防抖也是面試時常常考到的知識點,這篇文章為大家進行了詳細介紹,需要的可以參考一下2023-05-05