如果您查看相关网站的页面源代码,您将看到它使用了gibberish-aes javascript库。要看到你需要做什么才能使其发挥作用,你必须研究它的功能。
翻看它的source code,它似乎使用随机盐进行加密。这个由字符串Salted__
作为前缀的格式在基本编码之前形成了密码文本的开始。
randArr = function(num) {
var result = [], i;
for (i = 0; i < num; i++) {
result = result.concat(Math.floor(Math.random() * 256));
}
return result;
},
和
enc = function(string, pass, binary) {
// string, password in plaintext
var salt = randArr(8),
pbe = openSSLKey(s2a(pass, binary), salt),
key = pbe.key,
iv = pbe.iv,
cipherBlocks,
saltBlock = [[83, 97, 108, 116, 101, 100, 95, 95].concat(salt)];
string = s2a(string, binary);
cipherBlocks = rawEncrypt(string, key, iv);
// Spells out 'Salted__'
cipherBlocks = saltBlock.concat(cipherBlocks);
return Base64.encode(cipherBlocks);
},
对于解密,它使用拾取盐的随机部分出来的密文的开始BASE64解码(第一slice
运算符)之后:
dec = function(string, pass, binary) {
// string, password in plaintext
var cryptArr = Base64.decode(string),
salt = cryptArr.slice(8, 16),
pbe = openSSLKey(s2a(pass, binary), salt),
key = pbe.key,
iv = pbe.iv;
cryptArr = cryptArr.slice(16, cryptArr.length);
// Take off the Salted__ffeeddcc
string = rawDecrypt(cryptArr, key, iv, binary);
return string;
},
现在缺失的部分是openSSLkey
功能:
openSSLKey = function(passwordArr, saltArr) {
// Number of rounds depends on the size of the AES in use
// 3 rounds for 256
// 2 rounds for the key, 1 for the IV
// 2 rounds for 128
// 1 round for the key, 1 round for the IV
// 3 rounds for 192 since it's not evenly divided by 128 bits
var rounds = Nr >= 12 ? 3: 2,
key = [],
iv = [],
md5_hash = [],
result = [],
data00 = passwordArr.concat(saltArr),
i;
md5_hash[0] = GibberishAES.Hash.MD5(data00);
result = md5_hash[0];
for (i = 1; i < rounds; i++) {
md5_hash[i] = GibberishAES.Hash.MD5(md5_hash[i - 1].concat(data00));
result = result.concat(md5_hash[i]);
}
key = result.slice(0, 4 * Nk);
iv = result.slice(4 * Nk, 4 * Nk + 16);
return {
key: key,
iv: iv
};
},
所以基本上你必须将openSSLKey
函数翻译成Python,并为它提供密码和盐。这会创建一个(key,iv)元组。使用这些来加密您的数据。将字符串Salted__
和salt加密到使用base64进行编码之前。那么它应该工作,我想。
你尝试过不同的模式吗?我看不到该网站是使用XTS,CBC还是仅使用ECB。尝试不同的模式。请注意,您使用IV,但该网站不会要求提供一个。 – javex
你需要给解密器IV。该网站不接受IV。所以它可能使用ECB,而不是CBC。 –
另外,你如何知道该网站将密文作为base64? –