mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 11:02:28 +08:00
fix compatibility for old encrypted data
This commit is contained in:
parent
9d32cd36ee
commit
4b7445be8e
@ -16,7 +16,7 @@ function decryptString(dataKey: any, cipherText: any) {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
function decrypt(key: any, cipherText: any, ivLength = 16) {
|
function decrypt(key: any, cipherText: any) {
|
||||||
if (cipherText === null) {
|
if (cipherText === null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -27,6 +27,8 @@ function decrypt(key: any, cipherText: any, ivLength = 16) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const cipherTextBufferWithIv = Buffer.from(cipherText.toString(), "base64");
|
const cipherTextBufferWithIv = Buffer.from(cipherText.toString(), "base64");
|
||||||
|
// old encrypted data can have IV of length 13, see some details here: https://github.com/zadam/trilium/issues/3017
|
||||||
|
const ivLength = cipherTextBufferWithIv.length % 16 === 0 ? 16 : 13;
|
||||||
const iv = cipherTextBufferWithIv.slice(0, ivLength);
|
const iv = cipherTextBufferWithIv.slice(0, ivLength);
|
||||||
|
|
||||||
const cipherTextBuffer = cipherTextBufferWithIv.slice(ivLength);
|
const cipherTextBuffer = cipherTextBufferWithIv.slice(ivLength);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user