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 1 year has passed since last update.

Kms Encrypt Decrypt をCliで行う

Last updated at Posted at 2022-09-28

aws-cli で文字列をencrypt・decryptしたメモ。

Encrypt

1回目以下でためしたところ

aws kms encrypt --key-id 'kms key id' --plaintext 'my plain text' --profile 'my profile'
Invalid base64: "my plain text"

上のようなエラーになる。

そこで以下のようなコマンドでencryptコマンド実行する。

aws kms encrypt --cli-binary-format raw-in-base64-out --plaintext 'my plain text' --key-id 'kms key id' --profile 'my profile'

{
    "CiphertextBlob": "ciphertext...",
    "KeyId": "arn:aws:kms:ap-northeast-1:MY_AWS_ACCOUNT_ID:key/kms key id",
    "EncryptionAlgorithm": "SYMMETRIC_DEFAULT"
}

上のコマンドで正常に実行されて、CiphertextBlobを確認できる。

Decrypt

aws kms decrypt --key-id 'kms key id' --profile 'my profile' --ciphertext-blob "ciphertext..."

{
    "KeyId":"arn:aws:kms:ap-northeast-1:MY_AWS_ACCOUNT_ID:key/kms key id",
    "Plaintext": "bXkgcGxhaW4gdGV4dA==",
    "EncryptionAlgorithm": "SYMMETRIC_DEFAULT"
}

このようにPlaintextがbase64で表示される。

aws kms decrypt --key-id 'kms key id' --profile 'my profile' --ciphertext-blob "ciphertext..." --query Plaintext --output text | base64 -d

my plain text

decryptして入力の文字列と同じ値になっていること確認できました。

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?