0

I try to encode and decode plaintext using aws kms encrypt and decrypt.But it showing a following error:

aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:

aws help
aws <command> help
aws <command> \<subcommand> help

**Unknown options: --decode, >, ExampleEncryptedFile.txt, base64"**

Commands which i used:

    **aws kms encrypt --key-id 1234abcd-12ab-34cd-56ef-1234567890ab --
    plaintext mysecretpassword --output text --query 
       CiphertextBlob | base64 --decode > ExampleEncryptedFile**

If i use like the below it works:

        **aws kms encrypt --key-id 1234abcd-12ab-34cd-56ef-1234567890ab --
       plaintext fileb://ExamplePlaintextFile --output text --query 
        CiphertextBlob** 

       Decode also facing  issue like: **InvalidCiphertextException error** 

Thanks in advance!

zaph
  • 111,848
  • 21
  • 189
  • 228
jake
  • 333
  • 1
  • 4
  • 12

1 Answers1

0

Try these:

#Encrypt
#!/bin/bash
if [ -z $3 ]
 then
 echo 'Encrypt a file with AWS KMS'
 echo 'Usage: ./encrypt.sh <inputfile> <outputfile>'
 echo 'Example: ./encrypt.sh input.txt output.txt'
 exit 1
fi


aws kms encrypt --key-id alias/**SOME_KEY_ALIAS** --plaintext fileb://$1 --output text --query CiphertextBlob | base64 --decode > $2

#####

# Decrypt
#!/bin/bash
if [ -z $2 ]
 then
 echo 'Decrypt a file with AWS KMS'
 echo 'Usage: ./decrypt.sh <inputfile> <outputfile>'
 echo 'Example: ./decrypt.sh input.txt output.txt'
 exit 1
fi
aws kms decrypt --ciphertext-blob fileb://$1 --output text --query Plaintext | base64 --decode > $2
SteveM
  • 66
  • 1
  • 3