动态密文-加解密

原创
08/12 14:20
阅读数 62
import console; 
import crypt;
import crypt.bin;

math.randomize();

var passport_key = function(str,encrypt_key){
	var encrypt_key = crypt.md5(encrypt_key,false);
	var j=1;
	var tmp = "";
	for(i=1;#str;1){
		j = j%32:32;
		tmp ++= string.pack(string.unpack(string.split(str)[i])^string.unpack(string.split(encrypt_key)[j]));
		j++;
	}
	return tmp;
}

var passport_encrypt = function(str,key="bob"){
	var encrypt_key = string.random(32,"0123456789abcdef");
	var j=1;
	var tmp = "";
	for(i=1;#str;1){
		j = j%32:32;
		tmp ++= string.split(encrypt_key)[j]++string.pack(string.unpack(string.split(str)[i])^string.unpack(string.split(encrypt_key)[j]));
		j++;
	}
	return crypt.bin.encodeUrlBase64(passport_key(tmp,key)); 	
}

var passport_decrypt = function(str,key="bob"){
	var str = passport_key(crypt.bin.decodeUrlBase64(str),key);
	var tmp = "";
	for(i=1;#str;1){
		md5 = string.split(str)[i];
		i++;
		tmp ++= string.pack(string.unpack(string.split(str)[i])^string.unpack(md5));
	}
	return tmp; 	
}

a = passport_encrypt("www.aardio.com");
console.log(a,passport_decrypt(a));

console.pause(true);

还有一种方式


encryptPwd = function(pwd,keystr = "aardiomvc"){//加密
	var des = ..crypt.des();
	des.setPassword(keystr)
	pwd = des.encrypt(pwd);
	pwd = ..crypt.bin.encodeBase64(pwd);
	return pwd;
}

decryptPwd = function(pwd,keystr = "aardiomvc"){//解密
	var des = ..crypt.des();
	des.setPassword(keystr);
	pwd = ..crypt.bin.decodeBase64(pwd);
	pwd = des.decrypt(pwd);
	return pwd;
}

 

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部