Last active
March 19, 2021 00:12
-
-
Save hxss/7a196aeaa1df703e1a3117a88e5dd7eb to your computer and use it in GitHub Desktop.
python cryptography encrypt pem issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from cryptography.hazmat.primitives import ( | |
serialization, | |
hashes, | |
) | |
from cryptography.hazmat.primitives.asymmetric import ( | |
rsa, | |
padding, | |
) | |
_private_key = rsa.generate_private_key( | |
public_exponent = 65537, | |
key_size = 2048, | |
) | |
_padding = padding.OAEP( | |
mgf = padding.MGF1(algorithm = hashes.SHA256()), | |
algorithm = hashes.SHA256(), | |
label = None | |
) | |
_pem = _private_key\ | |
.public_key()\ | |
.public_bytes( | |
encoding = serialization.Encoding.PEM, | |
format = serialization.PublicFormat.SubjectPublicKeyInfo | |
) | |
message = _private_key.public_key().encrypt( | |
_pem, | |
_padding | |
) | |
print(message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment