【问题标题】:Protecting my RSA Private Key Password when decrypting data解密数据时保护我的 RSA 私钥密码
【发布时间】:2014-07-17 19:33:08
【问题描述】:

我生成了用于加密目的的公钥和私钥。有一个密码短语连接到私钥,但我知道我不应该像这样以纯文本形式显示它。

我应该怎么做才能保护这个密码,使它不以纯文本形式显示?

// $data = encrypted data using RSA public key
// $key = the key that came along with the encrypted data

// find private key
$pkeyid = openssl_get_privatekey("file:///path/to/private.pem", "PASSWORD");

// try and decrypt the data using private key
openssl_open($data, $decrypted_data, $key, $pkeyid);

// if all went well, show decrypted data
echo $decrypted_data;

【问题讨论】:

    标签: php encryption rsa


    【解决方案1】:

    有多种方法可以做到这一点,您需要在多大程度上保护您的密码?

    为什么不将其保存在安全文件中,并在需要时读取它?

    以下是您可以通过的级别列表,以确保最大程度地保护主密钥。每一步都会为上一步增加更多保护。

    1. 在安全服务器上的存储库中隔离主密钥
    2. 限制对包含主密钥的服务器的访问
    3. 加密存储库中的主密钥。 (见Red Key/Black Key
    4. 主密钥的随机性和频繁更换

    【讨论】:

    • 感谢 Irb 的评论。主密钥是指获取私钥的密码吗?
    • 是的,指的是密码。