development:security:rsa:csr
CSR and signed certificate
# generate new RSA private key openssl genrsa -out private.pem 1024 # CSR and signed certificate are needed to export as PKCS12 store openssl req -new -key private.pem -out certificate.csr openssl x509 -req -days 365 -in certificate.csr -signkey private.pem -out certificate.crt # export as PKCS12 keystore openssl pkcs12 -export -out keystore.pfx -inkey private.pem -in certificate.crt -passout pass:password
Để đảm bảo chứng chỉ và private key khớp nhau, dùng lệnh sau, tránh bị lỗi “Error: curl: (58) unable to set private key file: 'server.key' type PEM”:
% openssl rsa -noout -modulus -in private.pem | openssl md5 MD5(stdin)= 5850122413002ab1fdc5d703638f55a8 % openssl x509 -noout -modulus -in certificate.crt | openssl md5 MD5(stdin)= 5850122413002ab1fdc5d703638f55a8
https://michaelheap.com/curl-58-unable-to-set-private-key-file-server-key-type-pem
Example:
tungnt@TungNTs-MacBook-Pro transfer % openssl genrsa -des3 -out vpb_private_key.key 2048 Generating RSA private key, 2048 bit long modulus (2 primes) ..........................................................................................+++++ ..+++++ e is 65537 (0x010001) Enter pass phrase for vpb_private_key.key: Verifying - Enter pass phrase for vpb_private_key.key: tungnt@TungNTs-MacBook-Pro vpb % openssl req -new -key vpb_private_key.key -out vpb_private_key.csr Enter pass phrase for vpb_private_key.key: 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]:VI State or Province Name (full name) [Some-State]:Ha Noi Locality Name (eg, city) []:Ha Noi Organization Name (eg, company) [Internet Widgits Pty Ltd]:NPay Organizational Unit Name (eg, section) []:NKT Common Name (e.g. server FQDN or YOUR name) []: Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: tungnt@TungNTs-MacBook-Pro vpb % openssl req -new -x509 -days 1001 -key vpb_private_key.key -sha256 -out vpb_public_key.cer Enter pass phrase for vpb_private_key.key: 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]:VI State or Province Name (full name) [Some-State]:Ha Noi Locality Name (eg, city) []:Ha Noi Organization Name (eg, company) [Internet Widgits Pty Ltd]:NPay Organizational Unit Name (eg, section) []:NKT Common Name (e.g. server FQDN or YOUR name) []: Email Address []: tungnt@TungNTs-MacBook-Pro vpb % openssl req -new -x509 -nodes -sha256 -days 365 -key vpb_private_key.key -out vpb.cert Enter pass phrase for vpb_private_key.key: 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]:VI State or Province Name (full name) [Some-State]:Ha Noi Locality Name (eg, city) []:Ha Noi Organization Name (eg, company) [Internet Widgits Pty Ltd]:NPay Organizational Unit Name (eg, section) []:NKT Common Name (e.g. server FQDN or YOUR name) []: Email Address []:
development/security/rsa/csr.txt · Last modified: 2024/08/06 07:04 by 127.0.0.1