OpenSSLで秘密鍵、公開鍵の作成

RSAを用いて公開鍵暗号方式で暗号化、複合化を行う

1. 秘密鍵の作成
$ openssl genrsa -out private.pem 2048

※暗号化した秘密鍵の作成
$ openssl genrsa -out private_secure.pem -aes256 2048

2. 公開鍵の作成
$ openssl rsa -in private.pem -pubout -out public.pem

3. ファイルの準備
$ echo ‘hoge’ > file.txt

4. 公開鍵で暗号化
$ openssl rsautl -encrypt -inkey public.pem -pubin -in file.txt -out file.encrypted
$ hexdump file.encrypted

5. 秘密鍵で復号化
$ openssl rsautl -decrypt -inkey private.pem -in file.encrypted -out file.decrypted
$ cat file.decrypted
hoge