分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

js 加密方法Encrypt

发布时间:2023-09-06 01:35责任编辑:熊小新关键词:js
function Encrypt(str, pwd) { ???????if (str == "") return ""; ???????str = escape(str); ???????if (!pwd || pwd == "") { ???????????var pwd = "1234"; ???????} ???????pwd = escape(pwd); ???????if (pwd == null || pwd.length <= 0) { ???????????alert("Please enter a password with which to encrypt the message."); ???????????return null; ???????} ???????var prand = ""; ???????for (var I = 0; I < pwd.length; I++) { ???????????prand += pwd.charCodeAt(I).toString(); ???????} ???????var sPos = Math.floor(prand.length / 5); ???????var mult = parseInt(prand.charAt(sPos) + prand.charAt(sPos * 2) + prand.charAt(sPos * 3) + prand.charAt(sPos * 4) + prand.charAt(sPos * 5)); ???????var incr = Math.ceil(pwd.length / 2); ???????var modu = Math.pow(2, 31) - 1; ???????if (mult < 2) { ???????????alert("Algorithm cannot find a suitable hash. Please choose a different password. /n Possible considerations are to choose a more complex or longer password."); ???????????return null; ???????} ???????var salt = Math.round(Math.random() * 1000000000) % 100000000; ???????prand += salt; ???????while (prand.length > 10) { ???????????prand = (parseInt(prand.substring(0, 10)) + parseInt(prand.substring(10, prand.length))).toString(); ???????} ???????prand = (mult * prand + incr) % modu; ???????var enc_chr = ""; ???????var enc_str = ""; ???????for (var I = 0; I < str.length; I++) { ???????????enc_chr = parseInt(str.charCodeAt(I) ^ Math.floor((prand / modu) * 255)); ???????????if (enc_chr < 16) { ???????????????enc_str += "0" + enc_chr.toString(16); ???????????} else ???????????????enc_str += enc_chr.toString(16); ???????????prand = (mult * prand + incr) % modu; ???????} ???????salt = salt.toString(16); ???????while (salt.length < 8) salt = "0" + salt; ???????enc_str += salt; ???????return enc_str; ???}

调用:Encrypt(name, " ")

js 加密方法Encrypt

原文地址:https://www.cnblogs.com/wjm956/p/8266845.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved