ruby/example_code/s3/s3_add_cspk_encrypt_item.rb
def run_me
  key_strings = create_public_private_rsa_key_pair_strings
  public_key_string = key_strings['public_key_string']
  public_key_file = 'my-public-key.pem'
  private_key_string = key_strings['private_key_string']
  private_key_file = 'my-private-key.pem'
  content_to_encrypt = 'Hello, World!'
  bucket_name = 'doc-example-bucket'
  object_key = 'my-file.txt'
  region = 'us-west-2'
  s3_client = Aws::S3::Client.new(region: region)

  unless public_private_rsa_key_pair_files_created?(
    public_key_string,
    public_key_file,
    private_key_string,
    private_key_file
  )
    puts 'Program will stop.'
    exit 1
  end

  encrypted_content = encrypt_and_return_object_content(
    public_key_file,
    content_to_encrypt
  )
  puts "Encrypted representation of '#{content_to_encrypt}' is:"
  puts encrypted_content

  if encrypted_object_uploaded?(
    s3_client,
    bucket_name,
    object_key,
    encrypted_content
  )
    puts 'Uploaded.'
  else
    puts 'Not uploaded.'
  end
end
# Full example call:
# Replace us-west-2 with the AWS Region you're using for Amazon S3.

Full example call:
Replace us-west-2 with the AWS Region you're using for Amazon S3.
Full example call : Replace us - west - 2 with the AWS Region you ' re using for Amazon S3 .
def run_me
  key_strings = create_public_private_rsa_key_pair_strings
  public_key_string = key_strings['public_key_string']
  public_key_file = 'my-public-key.pem'
  private_key_string = key_strings['private_key_string']
  private_key_file = 'my-private-key.pem'
  content_to_encrypt = 'Hello, World!'
  bucket_name = 'doc-example-bucket'
  object_key = 'my-file.txt'
  region = 'us-west-2'
  s3_client = Aws::S3::Client.new(region: region)
  unless public_private_rsa_key_pair_files_created?(
    public_key_string,
    public_key_file,
    private_key_string,
    private_key_file
  )
    puts 'Program will stop.'
    exit 1
  end
  encrypted_content = encrypt_and_return_object_content(
    public_key_file,
    content_to_encrypt
  )
  puts "Encrypted representation of '#{content_to_encrypt}' is:"
  puts encrypted_content
  if encrypted_object_uploaded?(
    s3_client,
    bucket_name,
    object_key,
    encrypted_content
  )
    puts 'Uploaded.'
  else
    puts 'Not uploaded.'
  end
end
def run_me key_strings = create_public_private_rsa_key_pair_strings public_key_string = key_strings [ 'public_key_string' ] public_key_file = 'my-public-key.pem' private_key_string = key_strings [ 'private_key_string' ] private_key_file = 'my-private-key.pem' content_to_encrypt = 'Hello, World!' bucket_name = 'doc-example-bucket' object_key = 'my-file.txt' region = 'us-west-2' s3_client = Aws :: S3 :: Client . new ( region : region ) unless public_private_rsa_key_pair_files_created? ( public_key_string , public_key_file , private_key_string , private_key_file ) puts 'Program will stop.' exit 1 end encrypted_content = encrypt_and_return_object_content ( public_key_file , content_to_encrypt ) puts "Encrypted representation of '#{content_to_encrypt}' is:" puts encrypted_content if encrypted_object_uploaded? ( s3_client , bucket_name , object_key , encrypted_content ) puts 'Uploaded.' else puts 'Not uploaded.' end end
Full example call:
Replace us-west-2 with the AWS Region you're using for Amazon S3.
Full example call : Replace us - west - 2 with the AWS Region you ' re using for Amazon S3 .