Skip to content
Pak Cyberbot edited this page Jan 3, 2024 · 2 revisions

It contains all the authentication related functions/classes.

checkpass()

This function verifies the availability of the sudo token. If present, it takes no action; otherwise, it displays a GUI dialog box to enter the sudo password (maximum tries: 3).

from csilibs.auth import checkpass

checkpass()

2024-01-03 14_52_50-VirtualBoxVM

gen_md5()

This function takes a file path as input and simply computes the MD5 hash of it.

gen_key()

Takes a password as an argument and returns the key derived from that password for the Fernet() function to use. This key is utilized by the encrypt & decrypt functions below.

encrypt()

Takes the return value of gen_key(), the plain file path, and the resulting encrypted file path as arguments. It also deletes the plain file after encrypting it, so use it carefully.

decrypt()

Takes the return value of gen_key(), the encrypted file path, and the resulting decrypted file path as arguments.

Usage Example

from csilibs.auth import gen_key, encrypt, decrypt

derived_key = gen_key('password123!')

# Deletes the secret.txt file after encryption
encrypt(derived_key,'/opt/CSI-Libs/secret.txt','/opt/CSI-Libs/secret.enc')

# Does not delete the secret.enc file after decryption
decrypt(derived_key,'/opt/CSI-Libs/secret.enc','/opt/CSI-Libs/secret.txt')
Clone this wiki locally