Class: AWS::S3::Crypter

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/s3/crypter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cipher_name = 'aes-256-cbc') ⇒ Crypter

Returns a new instance of Crypter.



8
9
10
# File 'lib/aws/s3/crypter.rb', line 8

def initialize(cipher_name = 'aes-256-cbc')
  @cipher = OpenSSL::Cipher::Cipher.new(cipher_name)
end

Instance Attribute Details

#cipherObject (readonly)

Returns the value of attribute cipher.



6
7
8
# File 'lib/aws/s3/crypter.rb', line 6

def cipher
  @cipher
end

Instance Method Details

#decrypt_data(edata, key, iv) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/aws/s3/crypter.rb', line 23

def decrypt_data(edata, key, iv)
  cipher.decrypt

  cipher.key = key
  cipher.iv  = iv

  data = cipher.update(edata)
  data << cipher.final
  data.to_s
end

#encrypt_data(data) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/aws/s3/crypter.rb', line 12

def encrypt_data(data)
  cipher.encrypt

  key   = cipher.random_key
  iv    = cipher.random_iv
  edata = cipher.update(data)
  edata << cipher.final

  [edata, key, iv]
end