I'm working on a project to test keys generated and I need 512 and 256 bits rsa keys so this is my code :
from Crypto.PublicKey import RSA
passPhrase = "p@ssw0rd"
key = RSA.generate(256)
encrypted_key = key.export_key(passphrase=passPhrase, pkcs=8)
and this is the error that i get :
File /usr/lib/python3/dist-packages/Crypto/PublicKey/RSA.py:504, in RSAImplementation.generate(self, bits, randfunc, progress_func, e)
462 """Randomly generate a fresh, new RSA key.
463
464 :Parameters:
(...)
500 **e** is not odd or smaller than 2.
501 """
502 if bits < 1024 or (bits & 0xff) != 0:
503 # pubkey.getStrongPrime doesn't like anything that's not a multiple of 256 and >= 1024
--> 504 raise ValueError("RSA modulus length must be a multiple of 256 and >= 1024")
505 if e%2==0 or e<3:
506 raise ValueError("RSA public exponent must be a positive, odd integer larger than 2.")
ValueError: RSA modulus length must be a multiple of 256 and >= 1024
So to what i understand I can't generate keys inferior to 1024 bits
So i did some investigation and i saw that one of the solution is to recompile OpenSSL and change the value of crypto/rsa/rsa_local.h:14:#define RSA_MIN_MODULUS_BITS 512 to 256
but i want to know if there is another solution easier