I’m using the Python M2Crypto package to generate RSA keys.
>>> import M2Crypto
>>> rsa = M2Crypto.RSA.gen_key (2048, 65537)
.............................................................+++
............................+++
>>>
Notice that “openssl stuff”. To suppress writing to stdout/err I usually do:
sys.stdout = open(os.devnull, 'w')
sys.stderr = open(os.devnull, 'w')
That has no effect in this case. I’m assuming this has to do with the way M2Crypto is wrapping OpenSSL.
Is there a way to stop it?
I looked at the source
/M2Crypto/RSA.py, found out what your issue was, and then realized I could have just read the docs. Always check the documentation first!!!According to the docs for RSA.gen_key,
gen_keyhas an optional argument calledcallbackwhich allows you to specify a function to call whenevergen_keyis called (ostensibly to provide feedback to the user). The default value for this call back prints stuff tostdout. Change your function call to:And it should do the trick.
EDIT
Below is the relevant code from the M2PyCrypto source. Comments added by me.