Kms加密密码

时间:2017-10-27 13:32:33

标签: amazon-web-services base64 aws-kms amazon-kms

我尝试使用aws kms加密和解密来编码和解码明文。但它显示以下错误:

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"**

我使用的命令:

    **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** 

提前致谢!

1 个答案:

答案 0 :(得分:0)

试试这些:

#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