MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / encrypt

Function encrypt

web/pgadmin/utils/crypto.py:25–44  ·  view source on GitHub ↗

Encrypt the plaintext with AES method. Parameters: plaintext -- String to be encrypted. key -- Key for encryption.

(plaintext, key)

Source from the content-addressed store, hash-verified

23
24
25def encrypt(plaintext, key):
26 """
27 Encrypt the plaintext with AES method.
28
29 Parameters:
30 plaintext -- String to be encrypted.
31 key -- Key for encryption.
32 """
33
34 iv = os.urandom(iv_size)
35 cipher = Cipher(AES(pad(key)), CFB8(iv), default_backend())
36 encryptor = cipher.encryptor()
37
38 # If user has entered non ascii password (Python2)
39 # we have to encode it first
40 if isinstance(plaintext, str):
41 plaintext = plaintext.encode()
42
43 return base64.b64encode(iv + encryptor.update(plaintext) +
44 encryptor.finalize())
45
46
47def decrypt(ciphertext, key):

Callers 10

_password_checkFunction · 0.90
_set_valid_attr_valueMethod · 0.90
createMethod · 0.90
connectMethod · 0.90
change_passwordMethod · 0.90

Calls 2

padFunction · 0.85
updateMethod · 0.45

Tested by

no test coverage detected