File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change 1010# region imports
1111from cryptography import x509
1212from cryptography .hazmat .primitives import serialization , hashes
13- from cryptography .hazmat .primitives .serialization import load_pem_public_key
1413from cryptography .hazmat .primitives .asymmetric import padding , rsa
1514from cryptography .hazmat .primitives .ciphers import Cipher , algorithms , modes
1615from cryptography .hazmat .backends import default_backend
@@ -481,6 +480,9 @@ def _encrypt_rsa_aes(
481480 backend = default_backend ()
482481 )
483482
483+ if not isinstance (public_key , rsa .RSAPublicKey ):
484+ raise TypeError ("Public key must be an RSA public key for envelope encryption." )
485+
484486 # Generate a random AES key
485487 aes_key = os .urandom (32 ) # 256-bit AES key
486488
@@ -523,6 +525,9 @@ def _encrypt_rsa(
523525 backend = default_backend ()
524526 )
525527
528+ if not isinstance (public_key , rsa .RSAPublicKey ):
529+ raise TypeError ("Public key must be an RSA public key for encryption." )
530+
526531 ciphertext = public_key .encrypt (
527532 plaintext .encode (),
528533 padding .OAEP (
You can’t perform that action at this time.
0 commit comments