user307015
user307015

Reputation: 21

M2Crypto RSA.gen_key - feed a password from Python code

RSA.gen_key function always asks for password when it's used to generate keys. Is there a way to feed it the password from the python code instead of typing it manually?

Upvotes: 2

Views: 1836

Answers (2)

Sinthet
Sinthet

Reputation: 893

The only time it asks for a password is if you try to save a key and you choose to use a cipher. Just pass "cipher=None" as an argument.

For example:

key=RSA.gen_key(2048, 65537)
key.save_pem('./privkey',cipher=None)

But as Heikki said, key generation requires no password. Only saving if you choose to use encryption.

Upvotes: 3

Heikki Toivonen
Heikki Toivonen

Reputation: 31130

It does not ask for passwords as far as I know:

In [1]: from M2Crypto import RSA

In [2]: r=RSA.gen_key(1024, 65537)
..++++++
.......................................++++++

In [3]: 

If you don't like that output, you can provide a custom callback function. See documentation and tests.

If you mean that it asks for passphrase when calling save_pem() method, you are right: the default will ask for password. But again, you can provide your own callback that provides the password programmatically.

Upvotes: 1

Related Questions