2022-08-15 07:46:48 -04:00
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
# frozen_string_literal: true
2024-01-16 10:41:11 -05:00
2022-08-15 07:46:48 -04:00
# Purpose:
# decrypt_data.rb demonstrates how to decrypt a string
# using Amazon Key Management Services (AWS KMS) using the AWS SDK for Ruby.
# snippet-start:[kms.ruby.decryptBlob]
2024-09-25 15:25:54 -04:00
require 'aws-sdk-kms' # v2: require 'aws-sdk'
2022-08-15 07:46:48 -04:00
# Decrypted blob
2024-09-25 15:25:54 -04:00
blob = '01020200785d68faeec386af1057904926253051eb2919d3c16078badf65b808b26dd057c101747cadf3593596e093d4ffbf22434a6d00000068306606092a864886f70d010706a0593057020100305206092a864886f70d010701301e060960864801650304012e3011040c9d629e573683972cdb7d94b30201108025b20b060591b02ca0deb0fbdfc2f86c8bfcb265947739851ad56f3adce91eba87c59691a9a1'
blob_packed = [ blob ] . pack ( 'H*' )
2022-08-15 07:46:48 -04:00
2024-09-25 15:25:54 -04:00
client = Aws :: KMS :: Client . new ( region : 'us-west-2' )
2022-08-15 07:46:48 -04:00
resp = client . decrypt ( {
ciphertext_blob : blob_packed
} )
2024-09-25 15:25:54 -04:00
puts 'Raw text: '
2022-08-15 07:46:48 -04:00
puts resp . plaintext
# snippet-end:[kms.ruby.decryptBlob]