Created
July 31, 2025 14:39
-
-
Save Hermann-SW/3d7481e57a4f62a3c37d6a228deec0fc to your computer and use it in GitHub Desktop.
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
| """ pylinted, and code formatted with black """ | |
| from math import lcm | |
| from cryptography.hazmat.primitives.asymmetric import rsa | |
| from cryptography.hazmat.backends import default_backend | |
| from cryptography.hazmat.primitives import serialization | |
| # P and Q are prime factors of largest factored sofar RSA-250 | |
| # | |
| P = 641352894770715802787901901705773890848250147429434472081168596 * 10**62 | |
| P += 32024532344630238623598752668347708737661925585694639798853367 | |
| Q = 333720275949781565562260106053551142279407603447675546667845209 * 10**62 | |
| Q += 87023841729210037080257448673296881877565718986258036932062711 | |
| E = 0x10001 | |
| L = lcm(P - 1, Q - 1) | |
| private_key = rsa.RSAPrivateNumbers( | |
| p=P, | |
| q=Q, | |
| d=pow(E, -1, L), | |
| dmp1=pow(E, -1, P - 1), | |
| dmq1=pow(E, -1, Q - 1), | |
| iqmp=pow(Q, -1, P), | |
| public_numbers=rsa.RSAPublicNumbers(e=E, n=P * Q), | |
| ).private_key(default_backend()) | |
| pem = private_key.private_bytes( | |
| encoding=serialization.Encoding.PEM, | |
| encryption_algorithm=serialization.NoEncryption(), | |
| format=serialization.PrivateFormat.TraditionalOpenSSL, | |
| ) | |
| with open("private_key.pem", "wb") as f: | |
| f.write(pem) | |
| public_key = private_key.public_key() | |
| pem = public_key.public_bytes( | |
| encoding=serialization.Encoding.PEM, | |
| format=serialization.PublicFormat.SubjectPublicKeyInfo, | |
| ) | |
| with open("public_key.pem", "wb") as f: | |
| f.write(pem) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using openssl with deprecated rsautl can be seen in this gist comment:
https://gist.github.com/Hermann-SW/4aefd5b12ff179700bb6594ba25f9646?permalink_comment_id=5701082#gistcomment-5701082