rc4加密后是乱码的问题 加密 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 返回的是二进制数据,可以直接使用也可以 base64 编码使用 按 RC4 算法说明,你的代码应写作// $pwd密钥 $data需加密字符串function rc4_zz($data,$pwd="") { $key [] = ""; $box [] = ""; $cipher= ""; $pwd = str_pad($pwd, 256, chr(0)); //加上这句 $pwd_length = strlen ( $pwd ); $data_length = strlen ( $data ); for($i = 0; $i < 256; $i ++) { $key [$i] = ord ( $pwd [$i % $pwd_length] ); $box [$i] = $i; } for($j = $i = 0; $i < 256; $i ++) { $j = ($j + $box [$i] + $key [$i]) % 256; $tmp = $box [$i]; $box [$i] = $box [$j]; $box [$j] = $tmp; } for($a = $j = $i = 0; $i < $data_length; $i ++) { $a = ($a + 1) % 256; $j = ($j + $box [$a]) % 256; $tmp = $box [$a]; $box [$a] = $box [$j]; $box [$j] = $tmp; $k = $box [(($box [$a] + $box [$j]) % 256)]; $cipher .= chr ( ord ( $data [$i] ) ^ $k ); } return $cipher;} 如何用D7实现下面的密码加密过程啊?求高手帮忙写下代码,谢谢啦//加密模块var rsa = (function($){ var publicKey // 获取公钥 var getPubKey = function(callback){ if(publicKey) return callback(); $.post('/accounts/prelogin').always(function(json){ if(json && json.status == 'ok'){ publicKey = json.data if(callback) callback() } }) } // rsa加密 var encrypt = function(txt){ if(!publicKey) return txt var rsa = new RSA.RSAKey() rsa.setPublic(publicKey.n, publicKey.e) var res = rsa.encrypt(txt) res = RSA.linebrk( RSA.hex2b64(res) ) return res } return { publicKey: publicKey, encrypt: encrypt, getPubKey: getPubKey }})(jQuery);/*********************************KP邮箱注册插件v1.0作者: wangning1**********************************/;(function($){$.fn.emailRegister = function(options){options = $.extend({formEle: $(this),msgEle: $(this).find(".msg"),submitUrl : $(this).attr('action'),loginIdEle: $(this).find("input[name='loginId']"),pwdEle: $(this).find("input[name='password']"),repwdEle: $(this).find("input[name='repassword']"),captchaEle: $(this).find("input[name='captcha']"),protocal: $('#ereg-protocol'),success: $.noop}, options);var ERROR_MESSAGES = { "serverError": "服务器维护中(api),请稍后再试","accountServerError": "服务器维护中(account),请稍后再试","unknownError": "服务器错误","clientBadParams": "手机号格式不正确","mobileExists": "手机号已注册或已绑定过其它账号","sendMsgError": "短信服务器异常,请稍后再试","tooManyRequests": "您今天的短信请求太多","tooOften": "短信请求太频繁,请稍后再试","invalidCode": "无效的验证码",'captchaError' : '验证码错误',"invalidMobile": "无效的手机号,请检查您的输入","emptyPassword": "密码不能为空","passwordTooLong": "密码太长","noSuchUser": "操作失败,无此用户","bindMobileBefore": "手机号已注册或绑定过其它账号","needPassword": "用户邮箱为空,需要密码","anNotPassword": "用户有邮箱,不能输入密码","sameEmailRegisteredBefore": "该邮箱已注册"}; $('#change-code, #captcha').click(function() { $("#captcha").attr('src', '/captcha?' + new Date().getTime()) })function showMsg(Msg){options.msgEle.html(Msg);}$(this).submit(function(){return false;})$(this).submit(function(){if(checkLoginId() && checkPwd() && checkProtocol()){submit(); }})function submit() {var loginId = $.trim(options.loginIdEle.val());var pwd = $.trim(options.pwdEle.val());var captcha = $.trim(options.captchaEle.val());rsa.getPubKey(function(){ var para = { 'loginId': loginId, 'password': pwd, } if(true){ para.security = 1; para.loginId = rsa.encrypt(para.loginId); para.password = rsa.encrypt(para.password); para.captcha = captcha; }$.post(options.submitUrl, para, function(data){if(data.status == 'ok'){options.formEle.trigger('reset');options.success('注册成功');}else{if(typeof ERROR_MESSAGES[data.status] == 'string'){showMsg(ERROR_MESSAGES[data.status]); }else{showMsg('账号密码不正确,错误码:' + data.status); }}}, 'json');});}function checkLoginId() {var loginId = $.trim(options.loginIdEle.val());if('' === loginId) {showMsg('邮箱地址不能为空');return false;}if (!/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/i.test(loginId) && !/^1\d{10}$/i.test(loginId) ){showMsg('账号格式不正确');return false;} return true;}//检测是否同意注册协议function checkProtocol() {if(options.protocal.attr('checked') !== 'checked'){showMsg('请先阅读并同意注册协议');return false; }else{showMsg(' ');return true;}}function checkPwd() {var pwd = $.trim(options.pwdEle.val());var repwd = $.trim(options.repwdEle.val());if('' === pwd) {showMsg('密码不能为空');return false;}if(pwd.length < 6 ){showMsg('密码过短,不能小于6个字符');return false;}if(pwd.length > 32 ){showMsg('密码过长,不能大于32个字符');return false;}if('' === repwd) {showMsg('确认密码不能为空');return false;}if(pwd !== repwd ) {showMsg('两次密码不一致');return false;}return true;}}})(jQuery); php 城市站如何配置 php中读取和写入的问题 php截字符的问题,在线等 谁做过FLASH视频聊天或会议系统?无插件的。 mysql数据库保存为utf-8,页面输入简体字或繁体字,怎么能同时搜索到简繁体呢? php数组问题 请教:PHP 添加扩展模块 关于表格数据提交,如何组合为数组形式.求解决方案.如分不够,可再另开贴加分.在线等待............... php中怎样调用<script>标示的函数? 关于session 为什么,父类方法会提前执行。 PHP生成嵌套JSON
也可以 base64 编码使用
function rc4_zz($data,$pwd="") {
$key [] = "";
$box [] = "";
$cipher= "";
$pwd = str_pad($pwd, 256, chr(0)); //加上这句
$pwd_length = strlen ( $pwd );
$data_length = strlen ( $data );
for($i = 0; $i < 256; $i ++) {
$key [$i] = ord ( $pwd [$i % $pwd_length] );
$box [$i] = $i;
}
for($j = $i = 0; $i < 256; $i ++) {
$j = ($j + $box [$i] + $key [$i]) % 256;
$tmp = $box [$i];
$box [$i] = $box [$j];
$box [$j] = $tmp;
}
for($a = $j = $i = 0; $i < $data_length; $i ++) {
$a = ($a + 1) % 256;
$j = ($j + $box [$a]) % 256;
$tmp = $box [$a];
$box [$a] = $box [$j];
$box [$j] = $tmp;
$k = $box [(($box [$a] + $box [$j]) % 256)];
$cipher .= chr ( ord ( $data [$i] ) ^ $k );
}
return $cipher;
}
//加密模块
var rsa = (function($){
var publicKey
// 获取公钥
var getPubKey = function(callback){
if(publicKey) return callback();
$.post('/accounts/prelogin').always(function(json){
if(json && json.status == 'ok'){
publicKey = json.data
if(callback) callback()
}
})
} // rsa加密
var encrypt = function(txt){
if(!publicKey) return txt
var rsa = new RSA.RSAKey()
rsa.setPublic(publicKey.n, publicKey.e)
var res = rsa.encrypt(txt)
res = RSA.linebrk( RSA.hex2b64(res) )
return res
}
return {
publicKey: publicKey,
encrypt: encrypt,
getPubKey: getPubKey
}
})(jQuery);/*********************************
KP邮箱注册插件v1.0作者: wangning1
**********************************/;(function($){
$.fn.emailRegister = function(options){
options = $.extend({
formEle: $(this),
msgEle: $(this).find(".msg"),
submitUrl : $(this).attr('action'),
loginIdEle: $(this).find("input[name='loginId']"),
pwdEle: $(this).find("input[name='password']"),
repwdEle: $(this).find("input[name='repassword']"),
captchaEle: $(this).find("input[name='captcha']"),
protocal: $('#ereg-protocol'),
success: $.noop}, options);
var ERROR_MESSAGES = {
"serverError": "服务器维护中(api),请稍后再试",
"accountServerError": "服务器维护中(account),请稍后再试",
"unknownError": "服务器错误",
"clientBadParams": "手机号格式不正确",
"mobileExists": "手机号已注册或已绑定过其它账号",
"sendMsgError": "短信服务器异常,请稍后再试",
"tooManyRequests": "您今天的短信请求太多",
"tooOften": "短信请求太频繁,请稍后再试",
"invalidCode": "无效的验证码",
'captchaError' : '验证码错误',
"invalidMobile": "无效的手机号,请检查您的输入",
"emptyPassword": "密码不能为空",
"passwordTooLong": "密码太长",
"noSuchUser": "操作失败,无此用户",
"bindMobileBefore": "手机号已注册或绑定过其它账号",
"needPassword": "用户邮箱为空,需要密码",
"anNotPassword": "用户有邮箱,不能输入密码",
"sameEmailRegisteredBefore": "该邮箱已注册"
}; $('#change-code, #captcha').click(function() {
$("#captcha").attr('src', '/captcha?' + new Date().getTime())
})
function showMsg(Msg){
options.msgEle.html(Msg);
}$(this).submit(function(){
return false;
})$(this).submit(function(){
if(checkLoginId() && checkPwd() && checkProtocol()){
submit();
}
})function submit() {
var loginId = $.trim(options.loginIdEle.val());
var pwd = $.trim(options.pwdEle.val());var captcha = $.trim(options.captchaEle.val());rsa.getPubKey(function(){
var para = {
'loginId': loginId,
'password': pwd,
} if(true){
para.security = 1;
para.loginId = rsa.encrypt(para.loginId);
para.password = rsa.encrypt(para.password);
para.captcha = captcha;
}$.post(options.submitUrl, para, function(data){
if(data.status == 'ok'){
options.formEle.trigger('reset');
options.success('注册成功');
}else{
if(typeof ERROR_MESSAGES[data.status] == 'string'){
showMsg(ERROR_MESSAGES[data.status]);
}else{
showMsg('账号密码不正确,错误码:' + data.status);
}
}
}, 'json');
});
}function checkLoginId() {
var loginId = $.trim(options.loginIdEle.val());if('' === loginId) {
showMsg('邮箱地址不能为空');
return false;
}if (!/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/i.test(loginId) && !/^1\d{10}$/i.test(loginId) ){
showMsg('账号格式不正确');
return false;
} return true;
}
//检测是否同意注册协议
function checkProtocol() {if(options.protocal.attr('checked') !== 'checked'){
showMsg('请先阅读并同意注册协议');
return false;
}else{
showMsg(' ');
return true;
}}function checkPwd() {
var pwd = $.trim(options.pwdEle.val());
var repwd = $.trim(options.repwdEle.val());if('' === pwd) {
showMsg('密码不能为空');
return false;
}if(pwd.length < 6 ){
showMsg('密码过短,不能小于6个字符');
return false;
}if(pwd.length > 32 ){
showMsg('密码过长,不能大于32个字符');
return false;
}
if('' === repwd) {
showMsg('确认密码不能为空');
return false;
}if(pwd !== repwd ) {
showMsg('两次密码不一致');
return false;
}return true;
}}
})(jQuery);