Skip to content

Instantly share code, notes, and snippets.

@n0ts
Forked from ryu1kn/Makefile
Last active August 17, 2023 03:36
Show Gist options
  • Save n0ts/a7170cab284700788d7242ca5f361b51 to your computer and use it in GitHub Desktop.
Save n0ts/a7170cab284700788d7242ca5f361b51 to your computer and use it in GitHub Desktop.

Revisions

  1. n0ts revised this gist Jul 26, 2019. 1 changed file with 10 additions and 5 deletions.
    15 changes: 10 additions & 5 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    # How to encrypt/decrypt your text/blob secret with AWS KMS with AWS cli

    KEY_ID=alias/my-key
    # AWS_PROFILE=<profile> AWS_DEFAULT_REGION=<region> MY_KEY_ID=<kms key id> make (encrypt-text|decrypt-text|encrypt-blob|decrypt-blob)

    KEY_ID=$(MY_KEY_ID)
    SECRET_BLOB_PATH=fileb://my-secret-blob
    SECRET_TEXT="my secret text"

    @@ -9,16 +11,19 @@ DECRYPTED_SECRET_AS_BLOB=decrypted_secret_blob # Result of decrypt-blob target

    encrypt-text:
    aws kms encrypt --key-id ${KEY_ID} --plaintext ${SECRET_TEXT} --query CiphertextBlob --output text \
    | base64 --decode > ${ENCRYPTED_SECRET_AS_BLOB}
    | base64 -d > ${ENCRYPTED_SECRET_AS_BLOB}

    decrypt-text:
    aws kms decrypt --ciphertext-blob fileb://${ENCRYPTED_SECRET_AS_BLOB} --query Plaintext --output text \
    | base64 --decode
    | base64 -d

    encrypt-blob:
    aws kms encrypt --key-id ${KEY_ID} --plaintext ${SECRET_BLOB_PATH} --query CiphertextBlob --output text \
    | base64 --decode > ${ENCRYPTED_SECRET_AS_BLOB}
    | base64 -d > ${ENCRYPTED_SECRET_AS_BLOB}

    decrypt-blob:
    aws kms decrypt --ciphertext-blob fileb://${ENCRYPTED_SECRET_AS_BLOB} --query Plaintext --output text \
    | base64 --decode > ${DECRYPTED_SECRET_AS_BLOB}
    | base64 -d > ${DECRYPTED_SECRET_AS_BLOB}

    clean:
    rm -f ${ENCRYPTED_SECRET_AS_BLOB} ${DECRYPTED_SECRET_AS_BLOB}
  2. @ryu1kn ryu1kn revised this gist Apr 2, 2018. No changes.
  3. @ryu1kn ryu1kn revised this gist Feb 28, 2018. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -9,16 +9,16 @@ DECRYPTED_SECRET_AS_BLOB=decrypted_secret_blob # Result of decrypt-blob target

    encrypt-text:
    aws kms encrypt --key-id ${KEY_ID} --plaintext ${SECRET_TEXT} --query CiphertextBlob --output text \
    base64 --decode > ${ENCRYPTED_SECRET_AS_BLOB}
    | base64 --decode > ${ENCRYPTED_SECRET_AS_BLOB}

    decrypt-text:
    aws kms decrypt --ciphertext-blob fileb://${ENCRYPTED_SECRET_AS_BLOB} --query Plaintext --output text \
    base64 --decode
    | base64 --decode

    encrypt-blob:
    aws kms encrypt --key-id ${KEY_ID} --plaintext ${SECRET_BLOB_PATH} --query CiphertextBlob --output text \
    base64 --decode > ${ENCRYPTED_SECRET_AS_BLOB}
    | base64 --decode > ${ENCRYPTED_SECRET_AS_BLOB}

    decrypt-blob:
    aws kms decrypt --ciphertext-blob fileb://${ENCRYPTED_SECRET_AS_BLOB} --query Plaintext --output text \
    base64 --decode > ${DECRYPTED_SECRET_AS_BLOB}
    | base64 --decode > ${DECRYPTED_SECRET_AS_BLOB}
  4. @ryu1kn ryu1kn revised this gist Mar 4, 2017. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,24 @@
    # How to encrypt/decrypt your text/blob secret with AWS KMS with AWS cli

    KEY_ID=alias/my-key
    SECRET_BLOB=fileb://my-secret-blob
    SECRET_BLOB_PATH=fileb://my-secret-blob
    SECRET_TEXT="my secret text"

    ENCRYPTED_SECRET_AS_BLOB=./encrypted_secret_blob
    DECRYPTED_SECRET_AS_BLOB=./decrypted_secret_blob # Result of decrypt-blob target
    ENCRYPTED_SECRET_AS_BLOB=encrypted_secret_blob
    DECRYPTED_SECRET_AS_BLOB=decrypted_secret_blob # Result of decrypt-blob target

    encrypt-text:
    aws kms encrypt --key-id ${KEY_ID} --plaintext ${SECRET_TEXT} --query CiphertextBlob --output text \
    base64 --decode > ${ENCRYPTED_SECRET_AS_BLOB}

    decrypt-text:
    aws kms decrypt --ciphertext-blob fileb://${PATH_TO_SECRET} --query Plaintext --output text \
    aws kms decrypt --ciphertext-blob fileb://${ENCRYPTED_SECRET_AS_BLOB} --query Plaintext --output text \
    base64 --decode

    encrypt-blob:
    aws kms encrypt --key-id ${KEY_ID} --plaintext ${SECRET_BLOB} --query CiphertextBlob --output text \
    aws kms encrypt --key-id ${KEY_ID} --plaintext ${SECRET_BLOB_PATH} --query CiphertextBlob --output text \
    base64 --decode > ${ENCRYPTED_SECRET_AS_BLOB}

    decrypt-blob:
    aws kms decrypt --ciphertext-blob fileb://${PATH_TO_SECRET} --query Plaintext --output text \
    aws kms decrypt --ciphertext-blob fileb://${ENCRYPTED_SECRET_AS_BLOB} --query Plaintext --output text \
    base64 --decode > ${DECRYPTED_SECRET_AS_BLOB}
  5. @ryu1kn ryu1kn created this gist Mar 4, 2017.
    24 changes: 24 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    # How to encrypt/decrypt your text/blob secret with AWS KMS with AWS cli

    KEY_ID=alias/my-key
    SECRET_BLOB=fileb://my-secret-blob
    SECRET_TEXT="my secret text"

    ENCRYPTED_SECRET_AS_BLOB=./encrypted_secret_blob
    DECRYPTED_SECRET_AS_BLOB=./decrypted_secret_blob # Result of decrypt-blob target

    encrypt-text:
    aws kms encrypt --key-id ${KEY_ID} --plaintext ${SECRET_TEXT} --query CiphertextBlob --output text \
    base64 --decode > ${ENCRYPTED_SECRET_AS_BLOB}

    decrypt-text:
    aws kms decrypt --ciphertext-blob fileb://${PATH_TO_SECRET} --query Plaintext --output text \
    base64 --decode

    encrypt-blob:
    aws kms encrypt --key-id ${KEY_ID} --plaintext ${SECRET_BLOB} --query CiphertextBlob --output text \
    base64 --decode > ${ENCRYPTED_SECRET_AS_BLOB}

    decrypt-blob:
    aws kms decrypt --ciphertext-blob fileb://${PATH_TO_SECRET} --query Plaintext --output text \
    base64 --decode > ${DECRYPTED_SECRET_AS_BLOB}