Class: WSS4R::Security::Crypto::TripleDESSymmetricEncrypter

Inherits:
SymmetricEncrypter show all
Defined in:
lib/wss4r/security/crypto/cipher.rb

Instance Method Summary collapse

Methods inherited from SymmetricEncrypter

#encrypt_to_b64, #iv, #iv_b64, #key, #key=, #key_b64

Constructor Details

#initialize(key = nil, iv = nil) ⇒ TripleDESSymmetricEncrypter

Returns a new instance of TripleDESSymmetricEncrypter.



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/wss4r/security/crypto/cipher.rb', line 60

def initialize(key = nil, iv = nil)
  @cipher = Cipher.new("DES-EDE3-CBC")
  if (iv == nil)
    @iv = @cipher.random_iv()
  else
    @iv = iv
  end
  if (key == nil)
    @key = @cipher.random_key()
  else
    @key = key
  end
end

Instance Method Details

#algorithmObject



83
84
85
# File 'lib/wss4r/security/crypto/cipher.rb', line 83

def algorithm()
  Types::ALGORITHM_3DES_CBC
end

#decrypt(text) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/wss4r/security/crypto/cipher.rb', line 74

def decrypt(text)
  @cipher.decrypt(@key, @iv)
  @cipher.key = @key
  @cipher.iv = @iv
  cipher = @cipher.update(text[8..-1])
  cipher << @cipher.final()
  cipher    
end

#iv=(text_iv) ⇒ Object



87
88
89
# File 'lib/wss4r/security/crypto/cipher.rb', line 87

def iv=(text_iv)
  @iv = text_iv[0..7]
end