MCPcopy Create free account
hub / github.com/SecurityInnovation/PGPy / _encrypt

Function _encrypt

pgpy/symenc.py:18–35  ·  view source on GitHub ↗
(pt, key, alg, iv=None)

Source from the content-addressed store, hash-verified

16
17
18def _encrypt(pt, key, alg, iv=None):
19 if iv is None:
20 iv = b'\x00' * (alg.block_size // 8)
21
22 if alg.is_insecure:
23 raise PGPInsecureCipherError("{:s} is not secure. Do not use it for encryption!".format(alg.name))
24
25 if not alg.is_supported:
26 raise PGPEncryptionError("Cipher {:s} not supported".format(alg.name))
27
28 try:
29 encryptor = Cipher(alg.cipher(key), modes.CFB(iv), default_backend()).encryptor()
30
31 except UnsupportedAlgorithm as ex: # pragma: no cover
32 raise PGPEncryptionError from ex
33
34 else:
35 return bytearray(encryptor.update(pt) + encryptor.finalize())
36
37
38def _decrypt(ct, key, alg, iv=None):

Callers 3

encrypt_keyblobMethod · 0.85
encrypt_skMethod · 0.85
encryptMethod · 0.85

Calls 4

PGPEncryptionErrorClass · 0.85
cipherMethod · 0.80
updateMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…