【问题标题】:Generate RSA public and private key pair from a passpharse从密码短语生成 RSA 公钥和私钥对
【发布时间】:2020-08-04 04:40:41
【问题描述】:

我想从密码生成一个 RSA 密钥对。我怎样才能在 Python 中做到这一点。我尝试过 PBDFK2,但我只适用于 AES 等对称加密。

【问题讨论】:

    标签: python rsa


    【解决方案1】:

    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)
    

    或者你可以使用exec() function和命令行函数"ssh-keygen"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-15
      • 1970-01-01
      • 2011-07-11
      • 2014-04-26
      • 2023-01-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多