Encrypting Data in AWS KMS - AWS SDK for Ruby

Encrypting Data in AWS KMS

The following example uses the AWS SDK for Ruby encrypt method, which implements the Encrypt operation, to encrypt the string “1234567890”. The example displays a readable version of the resulting encrypted blob.

require "aws-sdk-kms" # v2: require 'aws-sdk' # ARN of the AWS KMS key. # # Replace the fictitious key ARN with a valid key ID keyId = "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab" text = "1234567890" client = Aws::KMS::Client.new(region: "us-west-2") resp = client.encrypt({ key_id: keyId, plaintext: text, }) # Display a readable version of the resulting encrypted blob. puts "Blob:" puts resp.ciphertext_blob.unpack("H*")

See the complete example on GitHub.