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

问题描述 投票:0回答:1

我有一个用于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 ----- END证书-----

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

所以结果是这样的:

----- BEGIN RSA私钥----- MIIEowIBAAKCAQEAmWAMkQeBjwD2BeanQ7ViMnQajaoQyRdHEcA6tszBiTK3xFFg QPE + + 7bW860wc1S Pf5hhipgZR55xMZCq27ULOOkW3MeAO7zEAZIitKod9P5BRCgXvezdqNL0Znz WMU / aK83dEsD1784mh4wft6a97o9T16DyudgAisJj1s83X8haTVZR Wyac8hxYv2aQreUV5987sN7ZX76jF1qYA / LAwskjbDa / GQ8CRXGRxmmxK5r4UsuW PI3Yv5ioWqj / 3soYY9dxpETsDNgrR1g00F8WJQIDAQABAoIBAApcRZ0KX8MUMopF GWJ eKql0yFcqpOa4e8eCBlPDYfCCE3XnWrsGONBKr9QX4CVJW6YYeqIqwZ5PiH7 TbyMZ5jeg8n03vJxPDIOZHblzpamAzoeZy + / + 1cKYxzbQ3WNdxdfpsDMvIPZdFL0B3 gvZzBh6SBIfN6RjRUmFcLCBBepj4SH1FORQxMxeSgYw4FdwBQKb ZHdXdlsIHnDV WZEn4cM0JjDu2vxOdq3BhhSh6fGvbL5DGZY CpdYqz6 + 64 + + + UHF3QSXoz0DVFS0YX A8gc3hkXnKa1m x5BOYtwWf CEM + / ENtDFHDyaH5qRRP4tWrzvSf2cXlJKqPJ9vl aVgqK4UCgYEA43 / rquhBZ00QzezyvEdnYKJf63IrqlBjYix96sBTEuMsPWjeGtKZ UsPbAoGBALeumtDCwCrTCbTdV44ThlLRXjTyY / p + gSmhI2jwSQzb8 TNH3BqoNVV MASLFnd + / + 5ZLXXVNMG3UFxpt75Tjw98fQFuXHLr46c8k9gC0kg sd8Ju2NMk0HcpB F1wig5Bn8kdxIC5fL2ss5sEhP9iEqAA5xYwQx0HZF7zre0Oe / AlDasdasdasdasdasasdassa ----- END RSA私钥-----

unix format ssl-certificate ascii
1个回答
1
投票

试试这个:

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

jq适用于所有主要发行版https://stedolan.github.io/jq/download/

© www.soinside.com 2019 - 2024. All rights reserved.