-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcryptverify.sh
More file actions
47 lines (25 loc) · 782 Bytes
/
cryptverify.sh
File metadata and controls
47 lines (25 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
encrypt_file()
{
file="$1"
encrypted_file="$file.enc"
passphrase="$2"
iv=$(openssl rand -hex 16)
openssl enc -aes-256-cbc -salt -in "$file" -out "$encrypted_file" -K "$(echo -n "$passphrase" | sha256sum | cut -d ' ' -f 1)" -iv "$iv"
echo "Archivo encriptado."
}
verify_integrity()
{
file="$1"
expected_hash="$2"
actual_hash=$(sha256sum "$file" | cut -d ' ' -f 1)
if [ "$actual_hash" == "$expected_hash" ]; then
echo "Integridad correcta."
else
echo "ERROR: La integridad no coincide."
fi
}
archivo="archivo.txt"
contraseña="mi_contraseña_secreta"
hash_esperado="HASH_ESPERADO_DEL_ARCHIVO"
encrypt_file "$archivo" "$contraseña"
verify_integrity "$archivo.enc" "$hash_esperado"