OpenSSL 사용하기

 

1. 개인키생성

 1) 3DES 로 암호화

    openssl genrsa -des3 -out KEYNAME.key 1024

[root@domU-12-31-39-14-F9-A2 bin]# openssl genrsa -des3 -out mykey.key 1024

Generating RSA private key, 1024 bit long modulus

…………………++++++

……………………..++++++

e is 65537 (0x10001)

Enter pass phrase for mykey.key:

Verifying – Enter pass phrase for mykey.key:

 

 

 2) 암호화 하지 않음

    openssl genrsa -out KEYNAME.key 1024

[root@domU-12-31-39-14-F9-A2 bin]# openssl genrsa -out test.key 1024

Generating RSA private key, 1024 bit long modulus

…………………………………………………………………………++++++

…………………………..++++++

e is 65537 (0x10001)

 

 

 3) 기존 비밀키에 패스워드 추가

    openssl rsa -in KEYNAME.key -des3 -out NEW_KEYNAME.key

[root@domU-12-31-39-14-F9-A2 bin]# openssl rsa -in mykey.key -des3 -out newmykey.key

Enter pass phrase for mykey.key:

writing RSA key

Enter PEM pass phrase:

Verifying – Enter PEM pass phrase:

 

 

 4) 기존 비밀키에 패스워드 제거

    openssl rsa -in KEYNAME.key -out NEW_KEYNAME.key

[root@domU-12-31-39-14-F9-A2 bin]# openssl rsa -in mykey.key -out nopassmykey.key

Enter pass phrase for mykey.key:

writing RSA key

 

 

 

2. CSR생성 (인증서 서명 요청)

  openssl req -new -key KEYNAME.key -out CSRNAME.csr

 

[root@domU-12-31-39-14-F9-A2 bin]# openssl req -new -key mykey.key -out mycsr.csr

Enter pass phrase for mykey.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) [XX]:xx

State or Province Name (full name) []:Seoul

Locality Name (eg, city) [Default City]:Seoul

Organization Name (eg, company) [Default Company Ltd]:Test company

Organizational Unit Name (eg, section) []:Test Service

Common Name (eg, your name or your server’s hostname) []:Test Server

Email Address []:eunsung.lim@gmail.com

 

Please enter the following ‘extra’ attributes

to be sent with your certificate request

A challenge password []:color

An optional company name []:Test Company

 

 

3. 자체 서명 인증서 생성하기

  openssl req -new -key KEYNAME.key -x509 -out CERT_NAME.crt

[root@domU-12-31-39-14-F9-A2 bin]# openssl req -new -key mykey.key -x509 -out server.crt

Enter pass phrase for mykey.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) [XX]:xx

State or Province Name (full name) []:Seoul

Locality Name (eg, city) [Default City]:Seoul

Organization Name (eg, company) [Default Company Ltd]:Test Company

Organizational Unit Name (eg, section) []:Test Service

Common Name (eg, your name or your server’s hostname) []:domU-12-31-39-14-F9-A2

 

 

 

4. 인증서 다루는 법

  1) 인증서 확인(보기)

    openssl x509 -noout -text -in CERT_NAME.crt

[root@domU-12-31-39-14-F9-A2 bin]# openssl x509 -noout -text -in server.crt

Certificate:

    Data:

        Version: 3 (0x2)

        Serial Number:

…..

….

 

  2) 비밀키 보기

    openssl rsa -noout -text -in KEYNAME.key

[root@domU-12-31-39-14-F9-A2 bin]# openssl rsa -noout -text -in mykey.key

Enter pass phrase for mykey.key:

Private-Key: (1024 bit)

modulus:

    00:a9:eb:af:3e:65:0a:57:d3:3a:c6:c3:84:62:da:

    47:a1:cb:4b:f9:0f:d4:4c:81:56:46:67:ac:dd:52:

…..