1. 程式人生 > 其它 >openssl生成證書

openssl生成證書

 

$ openssl genrsa > kevin.key
Generating RSA private key, 2048 bit long modulus (2 primes)
..................+++++
.+++++
e is 65537 (0x010001)

 

$ cat kevin.key 
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAy2QpLLv3whOL8o8QdFWbSxKe+2Afesqg2p/0R3EiI5LgLogM
2lxAHoTq8levAIwL5UjT/IVgOW4+iHUkmFtXnGbtuqn83Inl+G3IedulpW3bOryS
VX41JMKudszPjw0kY7MFIJyA1FQw3PSLF8yxrD4wnQPy1rWONFUM4vsE
+WBy/i/F 26kvt/RHrsTnADeQH0CDd4Hvai9YMuvBgxrHCIa4cAfX3q39ancdMUgJql/vzyJp IifraYQlPjfmoZ9wXttitSifkp71JKWDGVxyYqaNt5KI0VB7ut0m5tujQOjjWNi1 WhlZCduDM6HJEQeEo6SE71u8MCxbe60hi4SC5wIDAQABAoIBAFEKYsGZT9n7sdp/ GJ5R8eOS0tf0b/acQEV8UHga4vBruHmx6fUjpsTCT18qgudj5eWBBD5s4m9ftvjm PCOc2abO+FBVJRS2uXQoQiYT18e3ow+fTWtVM1WnYJ6jctxb7zDuhs98rHRt615O 7hEYlX689N
/LT/ovMy806EKUpGG8T4JiTIcD05wM0gD22Gf92QyivihzYLZfPsm5 DDvEe6RP9N/rB7fz4fWzAC/atx9d1Tc8keeFBOWytUORTWbGd/69Ccu9loPKOnL+ AIc5r0QVGdKPP7V5nfD9sMd/kZ9QnW6QygFdROmqUW5eZv9i0jOp9lGwK3tgYNg6 vsyqM+ECgYEA7C44t/Y9UBM0u7a5S3yoRgaPXys5XLWwO3PYNrPesft0St6uCed7 /7mEfpMycNdG0rUICZAqQhHwzd00ZfQanmkwuffkStxTiJ6vyfcdseX/3aqjRt4W hTdB2C92OmsfjMq
+tH+il6KmMvfjDGJW7xD6ggxCx7sV9ZywQO+i/NECgYEA3HWJ /Z6Exz5lHkn5nUU06P9VDJ7af0vnJV0whZ2NmD5+33x4XaMBnwM9NMKfhfY2/71a kMh/1DI31dyScEuaLzB3zYtD25rs9uNsJRkWJo3NwXmJnyKxJn8ZxAOTeaY6JmX2 tHjyAMEawTFiZNM4Nee30xuoveo2OlZcG9aBkjcCgYAEp/SeS9Bxn69OdA+7GT4I A2EYMzXySfKreWEt0uX1BEwKndE4iMO9Ct89z5ETAGt5A/Cgn6L1onzo0g+SYvmT XeeEAwsRHr7W1qoIhUKkmzAsIo0NfJtdDPXTWTwvcqUwlV6lGE8QRjiYkKJ9QAMO u3r0zWETpvCL4wbmgNLpwQKBgQDSUuC/MciDPafC6dhWjnwX/eDqFXNnFscDApEU KGe544WvOVSsIKOfTLvL5hHDAE8gVUpd7qrlirNyOOkMcVQ7yQXC9yZaEMgaEoZO LkzPo2G1P3poc/SGQaQXOUItQMUhdQ2Ux/45cgFQZwj0H/70joj1wuGNrjDmHxXp CRC8qQKBgQCjQlPd6ECEk2Bd0VPmHcsx/TDPGIkHtd8yRo7LyS2XBS2kkzh8Ue6V ugn1RrwxknPF7fVe3gJSxDXwlpH62kblPnMmMkQawzOwFhHnnjN3VoIdX9jlnSzH +tXaoQBNTt0nqCsg8SCpVswKORhZF00AN8NC5dwqRrEIO7RVyKanpQ== -----END RSA PRIVATE KEY-----

 

$ openssl req -new -x509 -key kevin.key > kevin.pem
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:china
string is too long, it needs to be no more than 2 bytes long
Country Name (2 letter code) [AU]:zh
State or Province Name (full name) [Some-State]:beijing
Locality Name (eg, city) []:beijing
Organization Name (eg, company) [Internet Widgits Pty Ltd]:mycompany
Organizational Unit Name (eg, section) []:iot
Common Name (e.g. server FQDN or YOUR name) []:matter.mycompany.com
Email Address []:[email protected]

 

$ cat kevin.pem 
-----BEGIN CERTIFICATE-----
MIID/TCCAuWgAwIBAgIUcko+f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