ruby/example_code/s3/s3-ruby-example-add-cspk-item.rb
# Replace us-west-2 with the AWS Region you're using for Amazon S3.

Replace us-west-2 with the AWS Region you're using for Amazon S3.
Replace us - west - 2 with the AWS Region you ' re using for Amazon S3 .
def run_me
  bucket_name = 'doc-example-bucket'
  object_key = 'my-file.txt'
  object_content = 'This is the content of my-file.txt.'
  region = 'us-west-2'
  public_key_file = 'my-public-key.pem'
  public_key = OpenSSL::PKey::RSA.new(File.read(public_key_file))
  s3_encryption_client = Aws::S3::EncryptionV2::Client.new(
    encryption_key: public_key,
    key_wrap_schema: :rsa_oaep_sha1,
    content_encryption_schema: :aes_gcm_no_padding,
    security_profile: :v2,
    region: region
  )
  if object_uploaded_with_public_key_encryption?(
    s3_encryption_client,
    bucket_name,
    object_key,
    object_content
  )
    puts 'Object uploaded.'
  else
    puts 'Object not uploaded.'
  end
end
def run_me bucket_name = 'doc-example-bucket' object_key = 'my-file.txt' object_content = 'This is the content of my-file.txt.' region = 'us-west-2' public_key_file = 'my-public-key.pem' public_key = OpenSSL :: PKey :: RSA . new ( File . read ( public_key_file ) ) s3_encryption_client = Aws :: S3 :: EncryptionV2 :: Client . new ( encryption_key : public_key , key_wrap_schema : :rsa_oaep_sha1 , content_encryption_schema : :aes_gcm_no_padding , security_profile : :v2 , region : region ) if object_uploaded_with_public_key_encryption? ( s3_encryption_client , bucket_name , object_key , object_content ) puts 'Object uploaded.' else puts 'Object not uploaded.' end end
Replace us-west-2 with the AWS Region you're using for Amazon S3.
Replace us - west - 2 with the AWS Region you ' re using for Amazon S3 .
# When initializing this Amazon S3 encryption client, note:
 # - For key_wrap_schema, use rsa_oaep_sha1 for asymmetric keys.
 # - For security_profile, for reading or decrypting objects encrypted
 #     by the v1 encryption client, use :v2_and_legacy instead.
