开发者

M2Crypto RSA.gen_key - feed a password from Python code

开发者 https://www.devze.com 2022-12-25 03:28 出处:网络
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开发者_如何学JAVA python code instead of typing it manually?The only time

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开发者_如何学JAVA python code instead of typing it manually?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号