Skip to content

Instantly share code, notes, and snippets.

@salrashid123
Created December 16, 2021 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salrashid123/8b4ac4dfa3ccb3252baa52f4dc6227d6 to your computer and use it in GitHub Desktop.
Save salrashid123/8b4ac4dfa3ccb3252baa52f4dc6227d6 to your computer and use it in GitHub Desktop.
Encrypt/Decrypt using RSA openssl and GCP Cloud KMS

given a key of type

gcloud kms keys list --keyring=mykeyring --location=us-central1
   projects/mineral-minutia-820/locations/us-central1/keyRings/mykeyring/cryptoKeys/dlp            ASYMMETRIC_DECRYPT  RSA_DECRYPT_OAEP_2048_SHA1    SOFTWARE
gcloud kms keys versions get-public-key 1 --key dlp --keyring=mykeyring --location=us-central1 > key.pub

echo -n "my ssn is 221-11-1234" > bar.txt

openssl rsautl -in bar.txt -out bar.enc -pubin -inkey key.pub -encrypt -oaep

 openssl base64 -in bar.enc

gcloud kms asymmetric-decrypt --ciphertext-file bar.enc --plaintext-file bar.dec  --key dlp --keyring=mykeyring --location=us-central1  --version 1
cat bar.dec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment