Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud KMS encryption got very different results between command line and java code

I am a beginner to google cloud. I have a java code which uses KMS to encrypt some credential information. At last it returns the cyphertext (a String object), which is what i need. It gives me something like this:

CiQAUxKMC06hZ7cuhlqdQQPGdNJqotwoKlSzjKmr+kwR3iMLg04SZABqmWMTCukKk0EVIDa1PpqqSIszczXGvt+nQN/jpV3DLEjXH3xkzdL0an9kiRIfLHryhcFwaYt/DczI4sy4VdZSoyKcszzZyGdVjISsyIbMnYINuqme1sa7GqLM98cXfnYzHjE=

EncryptResponse response = kms.projects().locations().keyRings().cryptoKeys()
            .encrypt(resourceName, request)
            .execute();
return response.getCiphertext();

Now I also want a bootstrap script that could do the similar thing. However, when I use command line as follows. The content in the encryption.txt file is not nice looking as a String, but some unicode characters. Is there a way I could achieve the above nice encryption string by using gcloud kms command line?

export ENCRYPTION=$(gcloud kms encrypt --location=global --keyring=$KEYRING --key=$KEY --plaintext-file=text.txt --ciphertext-file=encryption.txt)

like image 789
Ming.Yang Zhu Avatar asked May 31 '26 05:05

Ming.Yang Zhu


1 Answers

Google Cloud KMS uses Base64-encoded AES-256 encryption keys. You should be able to decode the cyphertext using the base64 library.

like image 63
Alex Avatar answered Jun 02 '26 21:06

Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!