Class: WSS4R::Security::Crypto::AESSymmetricEncrypter

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

Direct Known Subclasses

AES128SymmetricEncrypter

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) ⇒ AESSymmetricEncrypter

Returns a new instance of AESSymmetricEncrypter.



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/wss4r/security/crypto/cipher.rb', line 93

def initialize(key = nil, iv = nil)
  @cipher = Cipher.new(self.cipher_name)
  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



116
117
118
# File 'lib/wss4r/security/crypto/cipher.rb', line 116

def algorithm()
  Types::ALGORITHM_AES_CBC
end

#cipher_nameObject



120
121
122
# File 'lib/wss4r/security/crypto/cipher.rb', line 120

def cipher_name()
  "AES-256-CBC"
end

#decrypt(text) ⇒ Object



107
108
109
110
111
112
113
114
# File 'lib/wss4r/security/crypto/cipher.rb', line 107

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

#iv=(text_iv) ⇒ Object



124
125
126
# File 'lib/wss4r/security/crypto/cipher.rb', line 124

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