【问题标题】:pyOpenSSL RSA private keys encrypted with AES 256使用 AES 256 加密的 pyOpenSSL RSA 私钥
【发布时间】:2022-07-08 20:16:04
【问题描述】:

在 pyOpenSSL 中,我还没有找到使用 AES 256 加密 RSA 私钥的方法,一直在到处寻找,但似乎找不到方法。

在我使用 OpenSSL 获取密钥和 ca/cl 证书之前,但现在我选择制作一个需要以某些方式处理 pfx 文件的应用程序。

在 OpenSSL 中,我曾经做过以下事情:

openssl pkcs12 -in file.pfx -nocerts -out key.key

之后我做了:

openssl rsa -aes256 -key.key -out encrypted.key

pyOpenSSL 中是否有类似的东西使用加密?

【问题讨论】:

    标签: python encryption openssl pyopenssl


    【解决方案1】:

    我相信我解决了这个问题。我还有几个问题,因为我对此很陌生。但对于任何想知道的人,这就是我所做的:

    import os
    import shutil
    from Crypto.PublicKey import RSA
    
    
    def encrypt(old_key, new_key, passphrase):
            key = RSA.importKey(open(old_key, 'rb').read())
    
            with open(new_key, 'wb') as f:
                    pem_key = key.export_key(format='PEM', passphrase=passphrase, pkcs=8, protection='PBKDF2WithHMAC-SHA1AndAES256-CBC')
    
                    f.write(pem_key)
                    f.close()
    
            if os.path.exists(old_key):
                    os.remove(old_key)
    
    
    encryptAES('path_to_old_key', 'path_to_new:key.key', 'supersecretpassword')
    

    还有一个问题是,是否有办法输出类似于 OpenSSL 的 Python 中完成的加密信息?

    如果你运行openssl rsa -aes256 -in old.key -out new.key

    键将在开头返回属性,如下所示:

    -----开始 RSA 私钥-----
    Proc-Type:4,加密
    DEK 信息:AES-256-CBC
    关键在这里...
    -----结束 RSA 私钥-----

    但是,当我在 Python 中导出私钥时,我会得到:

    -----开始加密私钥----- 钥匙在这里... -----结束加密私钥-----

    有没有办法用 pycryptodome 显示这些属性?

    【讨论】:

      猜你喜欢
      • 2017-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多