Encrypting Data in Amazon KMS - Amazon SDK for Ruby
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Encrypting Data in Amazon KMS

The following example uses the Amazon 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.