0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

2022_0123.0.1 Opnessl

Last updated at Posted at 2022-01-23

環境:
Icon name: computer-vm
Chassis: vm
Machine ID: 6d12c80cd2cb0c409f7a3e4b8c6b71dc
Boot ID: c26be545d2d449f985a3263d896f6d8d
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1160.49.1.el7.x86_64
Architecture: x86-64

確認
$ yum list | grep openssl
openssl.x86_64 1:1.0.2k-22.el7_9 @updates
openssl-libs.x86_64 1:1.0.2k-22.el7_9 @updates

秘密鍵生成
$ openssl genrsa -des3 -out genrsa-des3.key 2048
Generating RSA private key, 2048 bit long modulus
..............+++
...................................................+++
e is 65537 (0x10001)
Enter pass phrase for sin-rsa-des3.key:
Verifying - Enter pass phrase for sin-rsa-des3.key:

秘密鍵から公開鍵を生成
$ openssl rsa -in genrsa-rsa-des3.key -pubout > pubkey.key
Enter pass phrase for sin-rsa-des3.key:
writing RSA key

RSA形式の公開鍵の内容を確認
$ openssl rsa -puboutin -in sin-rsa-pubkey.key -text
Public-Key: (2048 bit)
Modulus:
00:a6:df:27:3d:5d:c4:e0:85:2e:df:56:ef:f7:85:
<<秘密鍵内容>>
dd:df
Exponent: 65537 (0x10001)
writing RSA key
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApt8nPV3E4IUu31bv94U8
<<公開鍵内容>>
lrhe8xxh+c/oolAoIHk7AVww1p70e4Z4MTmHz9fnf8y5haUM/b0AueRJosS5tUjd
3wIDAQAB
-----END PUBLIC KEY-----

公開鍵を用いて暗号化
$ openssl rsautl -encrypt -pubin -inkey rsa-pubkey.key -in test -out test-rsa.txt

秘密鍵を用いて復号化
$ openssl rsautl -decrypt -inkey genrsa-des3.key -in test-rsa.txt -out test-decrypt.txt
Enter pass phrase for genrsa-des3.key:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?