refactored decryption to use a single file operation, increases performance extremely

pull/2/head
rjaeckel 8 years ago
parent 15bbe37986
commit d25fc4b5c8

@ -128,19 +128,16 @@ function decryptFile() {
# --- Get the FileKey --- # --- Get the FileKey ---
# --- Decrypt the file --- # --- Decrypt the file ---
# TODO: to figure out how to speed-up the decryption process. # OC writes the encrypted file in 8K chunks, each containing it's own iv in the end
# bottlenecks: chunkSize=8192
# - awk is running really slow, consuming lot of CPU while read -d '' -n $chunkSize CHUNK; do
encFileContentsALL="$(cat "${USER}/$encFilePath")" #split chunk into payload an iv string (strip padding from iv)
encFileContentsNOHEAD=$(echo -n "$encFileContentsALL" | sed -r 's/^HBEGIN:.+:HEND-*//') read payload iv <<<`echo $CHUNK | sed -r 's/(.*)00iv00(.{16})xx/\1 \2/'`
N=0 # convert base64 iv into hex
for IV in $(echo -n "$encFileContentsNOHEAD" |grep -E -o '00iv00.{16}xx' |sed -r 's/^00iv00//;s/xx$//'); do iv=$(echo -n "$iv" | od -An -tx1 | tr -dc '[:xdigit:]' )
N=$[N+1] # decode chunk
encFileContentsBASE64=$(echo -n "$encFileContentsNOHEAD" |awk -F '00iv00................xx' -v N=$N '{print $N}') openssl enc -AES-256-CFB -d -nosalt -base64 -A -K $decFileKeyContentHEX -iv $iv -in <(echo "$payload")
plainFileIVHEX=$(echo -n "$IV" |od -An -tx1 |tr -dc '[:xdigit:]') done <<<`sed -r 's/^HBEGIN:.+:HEND-*//' <"$encFilePath"` # pipe the encrypted file without head into the loop
openssl enc -AES-256-CFB -d -nosalt -base64 -A -K $decFileKeyContentHEX -iv $plainFileIVHEX -in <(echo "$encFileContentsBASE64")
#php -r "echo openssl_decrypt('$encFileContentsBASE64', 'AES-256-CFB', '$decFileKeyContent', false, '$IV');"
done
# --- Decrypt the file --- # --- Decrypt the file ---
} }

Loading…
Cancel
Save