bad attempt to read a stream using bash read byte by byte
This commit is contained in:
parent
2be33e7453
commit
250d59495b
30
ocdec.sh
30
ocdec.sh
@ -127,19 +127,27 @@ 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.
|
|
||||||
# bottlenecks:
|
|
||||||
# - awk is running really slow, consuming lot of CPU
|
|
||||||
encFileContentsALL="$(cat "${USER}/$encFilePath")"
|
encFileContentsALL="$(cat "${USER}/$encFilePath")"
|
||||||
encFileContentsNOHEAD=$(echo -n "$encFileContentsALL" | sed -r 's/^HBEGIN:.+:HEND-*//')
|
encFileContentsNOHEAD=$(echo -n "$encFileContentsALL" | sed -r 's/^HBEGIN:.+:HEND-*//')
|
||||||
N=0
|
|
||||||
for IV in $(echo -n "$encFileContentsNOHEAD" |grep -E -o '00iv00.{16}xx' |sed -r 's/^00iv00//;s/xx$//'); do
|
pos=0; posc=0; encStream="";
|
||||||
N=$[N+1]
|
# bottleneck: bash read by character is super slow
|
||||||
encFileContentsBASE64=$(echo -n "$encFileContentsNOHEAD" |awk -F '00iv00................xx' -v N=$N '{print $N}')
|
while IFS= read -r -n1 char; do
|
||||||
plainFileIVHEX=$(echo -n "$IV" |od -An -tx1 |tr -dc '[:xdigit:]')
|
(( posc++ ))
|
||||||
openssl enc -AES-256-CFB -d -nosalt -base64 -A -K $decFileKeyContentHEX -iv $plainFileIVHEX -in <(echo "$encFileContentsBASE64")
|
if $(echo ${encStream: -24} |grep -Eq "^00iv00.{16}xx$"); then
|
||||||
#php -r "echo openssl_decrypt('$encFileContentsBASE64', 'AES-256-CFB', '$decFileKeyContent', false, '$IV');"
|
plainIV=$(echo ${encStream: -24} |sed -r 's/^00iv00//;s/xx$//')
|
||||||
done
|
encStreamReady=${encStream:((posc - pos - 1)):((pos - 24))}
|
||||||
|
(( pos=0 ))
|
||||||
|
|
||||||
|
#echo "[::] DEBUG: " $encStreamReady with $plainIV
|
||||||
|
# can decrypt now
|
||||||
|
plainFileIVHEX=$(echo -n "$plainIV" |od -An -tx1 |tr -dc '[:xdigit:]')
|
||||||
|
openssl enc -AES-256-CFB -d -nosalt -base64 -A -K $decFileKeyContentHEX -iv $plainFileIVHEX -in <(echo "$encStreamReady")
|
||||||
|
#php -r "echo openssl_decrypt('$encStreamReady', 'AES-256-CFB', '$decFileKeyContent', false, '$plainIV');"
|
||||||
|
fi
|
||||||
|
(( pos++ ))
|
||||||
|
encStream="$encStream$char"
|
||||||
|
done <<< $encFileContentsNOHEAD
|
||||||
# --- Decrypt the file ---
|
# --- Decrypt the file ---
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user