Yah*_*din 4 database varchar openssl rsa
我在PHP中使用OpenSSL生成私钥和公钥,我打算将其存储在数据库中(尽管您可能不需要知道PHP来回答这个问题).
它们看起来像这样:
-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIFDjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIi4rlLSKA9/8CAggA
...
-----END ENCRYPTED PRIVATE KEY-----
Run Code Online (Sandbox Code Playgroud)
和
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA8YvAFZHSGNITeDNdXFbc
...
-----END PUBLIC KEY-----
Run Code Online (Sandbox Code Playgroud)
(是的,这只是例子)
他们是这样创建的:
$resource = openssl_pkey_new([
'private_key_bits' => '2048',
"private_key_type" => OPENSSL_KEYTYPE_RSA,
]);
openssl_pkey_export($resource, $privateKey, $passPhrase) === false
$opensslDetails = openssl_pkey_get_details($resource);
$publicKey = $opensslDetails['key'];
Run Code Online (Sandbox Code Playgroud)
我想知道这些私钥和公钥的最大长度是多少.
从我的实验中,我发现:
但是我没有找到任何关于此的正式文件来证明这种情况,所以我不能确定.
私有和公共RSA密钥的最大长度是多少?
从理论上讲,没有限制.在实践中,存在限制.此外,通常对模数大小(n = p*q)施加限制,而不是公钥或私钥本身.您的Web服务器或数据库可能面临其他限制.
对于OpenSSL和RSA,您的RSA密钥在生成时限制为16K.s_client
密钥交换期间使用的OpenSSL 实用程序也有限制.密钥交换期间的限制是2K,对我来说似乎人为的低.您可以s_client
通过避免密钥协议期间使用的密钥传输方案(即使用DH或EDH而不是RSA)来支持限制.
如果你开始达到极限,那么它通常表示切换到椭圆曲线的时间.16K RSA和521位EC提供大约512位的安全性.
另请参阅OpenSSL用户邮件列表中的RSA 16K模数的Openssl软件故障.
以下是使用从小(256位)到大(60K位)的Crypto ++库的 RSA密钥生成时间的一些事实.我相信这些数字是在5年前在Core2 Duo机器上收集的.OpenSSL应该具有渐近相似的运行时间.
cryptopp$ rsa_kgen.exe 61440
Elapsed time for 61140 RSA key: 25654.01s (7 hours, 7 minutes, 34 seconds)
cryptopp$ rsa_kgen.exe 30720
Elapsed time for 30720 RSA key: 2255.30s (37 minutes, 35 seconds)
cryptopp$ rsa_kgen.exe 15360
Elapsed time for 15360 RSA key: 285.05s (4 minutes, 45 seconds)
cryptopp$ rsa_kgen.exe 11776
Elapsed time for 11776 RSA key: 142.52s (2 minutes, 22 seconds)
cryptopp$ rsa_kgen.exe 8192
Elapsed time for 8192 RSA key: 43.08s (43 seconds)
cryptopp$ rsa_kgen.exe 4096
Elapsed time for 4096 RSA key: 0.70s
cryptopp$ rsa_kgen.exe 2048
Elapsed time for 2048 RSA key: 0.09s
cryptopp$ rsa_kgen.exe 1024
Elapsed time for 1024 RSA key: 0.01s
cryptopp$ rsa_kgen.exe 512
Elapsed time for 512 RSA key: 0.00s
cryptopp$ rsa_kgen.exe 256
Elapsed time for 256 RSA key: 0.00s
Run Code Online (Sandbox Code Playgroud)