从控制台输出格式化SSL证书?

时间:2019-04-03 11:31:04

标签: unix format ssl-certificate ascii

我有一个MySQL实例的PEM文件(请注意,此示例出于安全性考虑已更改) 它们被输出到控制台上的JSON字符串中。

PEM文件已使用换行符等的ASCII表示形式转义。

  

----- BEGIN CERTIFICATE ----- \ nMIIDfzCCAmegAwIBAgIBADANBgkqhkiG9w0BAQsFADB3MS0wKwYDVQQuEyQwMjI2 \ nNmQ5OC1jNmI2LTQxZGMtYTVmNi03OWJiNjMxOWMxYTQxIzAhBgNVBAMTGkdvb2ds \ nZSBDbG91ZCBTUUwgU2VydmVyIENBMRQwEgYDVQQKEwtHb29nbGUsIEluYzELMAkG \ nA1UEBhMCVVMwHhcNMTkwMzI5MTQwNDEwWhcNMjkwMzI2MTQwNTEwWjB3MS0wKwYD \ nVQQuEyQwMjI2NmQ5OC1jNmI2LTQxZGMtYTVmNi03OWJiNjMxOWMxYTQxIzAhBgNV \ nBAMTGkdvasdasdasdasdasdasdas6x15Ls6ntW9qhPy18vOsO81Dn \ nQON6GohHPhvf9TRqMZO9vQ06wZ5NO8 / xNfICPK0xmrGOPKwI0hHlRY + Vq5dzbGFE \ nynD4EQiyua6jDPwB8I8SCy7UUWxCIzlhpAHbSCZ2 / i2DdTpYfhzuxngM6kleyyOU \ nWEm843h6Lug / SEntVi7Y5stnAgMBAAGjFjAUMBIGA1UdEwEB / wQIMAYBAf8CAQAw \ nDQYJKoZIhvcNAQELBQADggEBAFzMYlOvLhNUPWkhqOzOZs1cNSv1kB + dswWkGA + / \ nci7j5pdjQheQoloXymP8XQUsY / 183huyAGPZiMX5BJ1wgpicbKB3RPfv / jcsCKfP \ nO3eEbKgXZDztOTG9Z7Tyj4a7m9Ka71HfylE4O2Pq5k3YuXfhozK60I8LirHraZnT \ N / CGSIe + xVk2EbWqf44lLJUYQqMZ2MrnXCbAmVNai6Bt8cWzF7J + 8itEojrt57229 \ n1th5TlMHOcKJhdWZiKoFA33UoosL0AcLDZU45K3TThn5 / dykLR7buU9JHXc3SC6n \ NPV / K / x7dz9sEoM + agSc9V7pCzcB8A / ImxFmOkqzCnIYkN5c = \ n -----结束   证书-----

这种格式的文件在使用SSL时无效,这是使用vim或其他合适的unix工具设置文本格式的最佳方法。

所以结果是这样的:

----- BEGIN RSA私钥----- MIIEowIBAAKCAQEAmWAMkQeBjwD2BeanQ7ViMnQajaoQyRdHEcA6tszBiTK3xFFg qPE + Pf5hhipgZR55xMZCq27ULOOkW3MeAO7zEAZIitKod9P5BRCgXvezdqNL0Znz WmU + 7bW860wc1S / aK83dEsD1784mh4wft6a97o9T16DyudgAisJj1s83X8haTVZR Wyac8hxYv2aQreUV5987sN7ZX76jF1qYA / LAwskjbDa / GQ8CRXGRxmmxK5r4UsuW PI3Yv5ioWqj / 3soYY9dxpETsDNgrR1g00F8WJQIDAQABAoIBAApcRZ0KX8MUMopF gWj + eKql0yFcqpOa4e8eCBlPDYfCCE3XnWrsGONBKr9QX4CVJW6YYeqIqwZ5PiH7 TbyMZ5jeg8n03vJxPDIOZHblzpamAzoeZy / 1cKYxzbQ3WNdxdfpsDMvIPZdFL0B3 gvZzBh6SBIfN6RjRUmFcLCBBepj4SH1FORQxMxeSgYw4FdwBQKb + ZHdXdlsIHnDV WZEn4cM0JjDu2vxOdq3BhhSh6fGvbL5DGZY + CpdYqz6 + 64 + UHF3QSXoz0DVFS0YX A8gc3hkXnKa1m + x5BOYtwWf + XHEM / ENtDFHDyaH5qRRP4tWrzvSf2cXlJKqPJ9vl aVgqK4UCgYEA43 / rquhBZ00QzezyvEdnYKJf63IrqlBjYix96sBTEuMsPWjeGtKZ UsPbAoGBALeumtDCwCrTCbTdV44ThlLRXjTyY / p + gSmhI2jwSQzb8 + TNH3BqoNVV MASLFnd / 5ZLXXVNMG3UFxpt75Tjw98fQFuXHLr46c8k9gC0kg + sd8Ju2NMk0HcpB F1wig5Bn8kdxIC5fL2ss5sEhP9iEqAA5xYwQx0HZF7zre0Oe / AlDasdasdasdasdasasdassa
-----结束RSA私钥-----

1 个答案:

答案 0 :(得分:1)

尝试一下:

jq -r '.json_path.to.your.private_key' your_json_file

jq在所有主要发行版https://stedolan.github.io/jq/download/中都可用