Ric*_*nks 35 javascript encryption obfuscation
我正在寻找一种在JavaScript中混淆和反混淆字符串的方法; 当安全性不是问题时,我的意思是加密和解密.理想的情况是一些原产于JS(像base64_encode()和base64_decode()在PHP)到"把字符串转换成别的,然后再返回的东西",而无需编写一个函数.
欢迎任何建议!
Min*_*hev 67
您可以使用btoa()和atob().btoa()是喜欢base64_encode()和atob()喜欢base64_decode().
这是一个例子:
btoa('Some text'); // U29tZSB0ZXh0
atob('U29tZSB0ZXh0'); // Some text
Run Code Online (Sandbox Code Playgroud)
请记住,这不是保密的安全方法.Base64是一种二进制到文本编码方案,通过将其转换为基数-64表示,以ASCII字符串格式表示二进制数据.
Gan*_*Man 19
值得注意的是
(![]+[])[+[]]+(![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]
评估字符串"fail"而不看起来像字符串.说真的,把它输入节点并感到惊讶.你可以疯狂地用JavaScript拼写任何东西.
enz*_*ian 11
我显然已经来不及回答,但我正在研究解决这个问题的另一个解决方案,而base64似乎很弱.
它的工作原理如下:
"abc;123!".obfs(13) // => "nopH>?@."
"nopH>?@.".defs(13) // => "abc;123!"
Run Code Online (Sandbox Code Playgroud)
代码:
/**
* Obfuscate a plaintext string with a simple rotation algorithm similar to
* the rot13 cipher.
* @param {[type]} key rotation index between 0 and n
* @param {Number} n maximum char that will be affected by the algorithm
* @return {[type]} obfuscated string
*/
String.prototype.obfs = function(key, n = 126) {
// return String itself if the given parameters are invalid
if (!(typeof(key) === 'number' && key % 1 === 0)
|| !(typeof(key) === 'number' && key % 1 === 0)) {
return this.toString();
}
var chars = this.toString().split('');
for (var i = 0; i < chars.length; i++) {
var c = chars[i].charCodeAt(0);
if (c <= n) {
chars[i] = String.fromCharCode((chars[i].charCodeAt(0) + key) % n);
}
}
return chars.join('');
};
/**
* De-obfuscate an obfuscated string with the method above.
* @param {[type]} key rotation index between 0 and n
* @param {Number} n same number that was used for obfuscation
* @return {[type]} plaintext string
*/
String.prototype.defs = function(key, n = 126) {
// return String itself if the given parameters are invalid
if (!(typeof(key) === 'number' && key % 1 === 0)
|| !(typeof(key) === 'number' && key % 1 === 0)) {
return this.toString();
}
return this.toString().obfs(n - key);
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31303 次 |
| 最近记录: |