Encrypting Data in AWS KMS - AWS SDK for Ruby

Encrypting Data in AWS KMS

The following example uses the AWS SDK for Rubyencrypt 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 customer master key (CMK). # # 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, }) puts 'Blob:' puts resp.ciphertext_blob.unpack('H*')

Choose Copy to save the code locally. See the complete example on GitHub.