mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 21:19:01 +01:00 
			
		
		
		
	Merge pull request #947 from TriliumNext/bugfix/dump-db-ivlength
Fix default ivLength in dump-db tool
This commit is contained in:
		
						commit
						66c367fe21
					
				@ -12,7 +12,7 @@ function getDataKey(password: any) {
 | 
			
		||||
 | 
			
		||||
        const encryptedDataKey = getOption("encryptedDataKey");
 | 
			
		||||
 | 
			
		||||
        const decryptedDataKey = decryptService.decrypt(passwordDerivedKey, encryptedDataKey, 16);
 | 
			
		||||
        const decryptedDataKey = decryptService.decrypt(passwordDerivedKey, encryptedDataKey);
 | 
			
		||||
 | 
			
		||||
        return decryptedDataKey;
 | 
			
		||||
    } catch (e: any) {
 | 
			
		||||
 | 
			
		||||
@ -16,7 +16,7 @@ function decryptString(dataKey: any, cipherText: any) {
 | 
			
		||||
    return str;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function decrypt(key: any, cipherText: any, ivLength = 13) {
 | 
			
		||||
function decrypt(key: any, cipherText: any) {
 | 
			
		||||
    if (cipherText === null) {
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
@ -27,6 +27,8 @@ function decrypt(key: any, cipherText: any, ivLength = 13) {
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
        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 cipherTextBuffer = cipherTextBufferWithIv.slice(ivLength);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user