Class: Xmlenc::Algorithms::DES3CBC

Inherits:
Object
  • Object
show all
Defined in:
lib/xmlenc/algorithms/des3_cbc.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key = nil) ⇒ DES3CBC

Returns a new instance of DES3CBC.



8
9
10
# File 'lib/xmlenc/algorithms/des3_cbc.rb', line 8

def initialize(key = nil)
  @key = key || cipher.random_key
end

Class Method Details

.setup(key) ⇒ Object



4
5
6
# File 'lib/xmlenc/algorithms/des3_cbc.rb', line 4

def self.setup(key)
  new(key)
end

Instance Method Details

#decrypt(cipher_value, options = {}) ⇒ Object



12
13
14
15
16
17
# File 'lib/xmlenc/algorithms/des3_cbc.rb', line 12

def decrypt(cipher_value, options = {})
  cipher.decrypt
  cipher.key = @key
  cipher.iv  = cipher_value[0...iv_len]
  cipher.update(cipher_value[iv_len..-1]) << cipher.final
end

#encrypt(data, options = {}) ⇒ Object



19
20
21
22
23
24
# File 'lib/xmlenc/algorithms/des3_cbc.rb', line 19

def encrypt(data, options = {})
  cipher.encrypt
  cipher.key = @key
  cipher.iv  = iv
  iv << cipher.update(data) << cipher.final
end

#keyObject



26
27
28
# File 'lib/xmlenc/algorithms/des3_cbc.rb', line 26

def key
  @key
end