Class: S3backup::Crypt

Inherits:
Object
  • Object
show all
Defined in:
lib/s3backup/crypt.rb

Constant Summary collapse

CIPHER_ALGORITHM =
"aes-256-cbc"

Instance Method Summary collapse

Constructor Details

#initialize(password, salt) ⇒ Crypt

Returns a new instance of Crypt.



5
6
7
8
# File 'lib/s3backup/crypt.rb', line 5

def initialize(password,salt)
  @password = password
  @salt = salt.scan(/../).map{|i|i.hex}.pack("c*")
end

Instance Method Details

#decrypt(data) ⇒ Object



15
16
17
18
19
20
# File 'lib/s3backup/crypt.rb', line 15

def decrypt(data)
  enc = OpenSSL::Cipher::Cipher.new(CIPHER_ALGORITHM)
  enc.decrypt
  enc.pkcs5_keyivgen(@password,@salt)
  enc.update(data)+enc.final
end

#encrypt(data) ⇒ Object



9
10
11
12
13
14
# File 'lib/s3backup/crypt.rb', line 9

def encrypt(data)
  enc = OpenSSL::Cipher::Cipher.new(CIPHER_ALGORITHM)
  enc.encrypt
  enc.pkcs5_keyivgen(@password,@salt)
  enc.update(data)+enc.final
end