Skip to content

Commit 7a48e7c

Browse files
committed
go back to try-catch for decryption check with "#" at substr(32,1)
1 parent 4b45c93 commit 7a48e7c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

encryptcontent/decrypt-contents.tpl.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ function decrypt_key(password, iv_b64, ciphertext_b64, salt_b64) {
1010
let encrypted = {ciphertext: ciphertext},
1111
cfg = {iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7};
1212
let key = CryptoJS.AES.decrypt(encrypted, kdfkey, cfg);
13-
if (key.sigBytes >= 32) {
14-
console.log(key.toString(CryptoJS.enc.Latin1).substr(32)); //remember_suffix + keystore_id after the AES key
15-
return key.toString(CryptoJS.enc.Hex).substr(0,64); //first 32 bytes contain the AES key
16-
} else {
13+
14+
try {
15+
let plaintext = key.toString(CryptoJS.enc.Latin1)
16+
if (plaintext.substr(32,1) == '#') {
17+
console.log(plaintext.substr(33)); //remember_suffix + keystore_id after the AES key
18+
return key.toString(CryptoJS.enc.Hex).substr(0,64); //first 32 bytes contain the AES key
19+
}
20+
} catch (err) {
21+
// encoding failed; wrong password
1722
return false;
1823
}
1924
};

0 commit comments

Comments
 (0)