简体   繁体   中英

Generate RSA public and private key pair from a passpharse

I want to generate a RSA key-pair from a passphrase. How can I do that in Python. I have try PBDFK2 but i works only for symmetric encryption like AES.

You could try using ezPyCrypto :

import ezPyCrypto

mysecret = "Secret"
raw = "String to Encrypt"

# Create a key object
k = ezPyCrypto.key(passphrase=mysecret)

# Export public/private key
publicAndPrivateKey = k.exportKeyPrivate()

# Encrypt against this keypair
enc = k.encString(raw)

# Create a new key object, and import keys (with passphrase)
k1 = ezPyCrypto.key(publicAndPrivateKey, passphrase=mysecret)

# Decrypt text
dec = k.decString(enc)

Or you can use the exec() function and commandline function "ssh-keygen" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM