Class: Owrb::Data::Cipher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cipher) ⇒ Cipher

Returns a new instance of Cipher.



218
219
220
221
222
# File 'lib/owrb.rb', line 218

def initialize( cipher )
  @cipher = cipher
  @key = ""
  @iv = ""
end

Instance Attribute Details

#cipherObject (readonly)

Returns the value of attribute cipher.



215
216
217
# File 'lib/owrb.rb', line 215

def cipher
  @cipher
end

#ivObject

Returns the value of attribute iv.



216
217
218
# File 'lib/owrb.rb', line 216

def iv
  @iv
end

#keyObject

Returns the value of attribute key.



216
217
218
# File 'lib/owrb.rb', line 216

def key
  @key
end

Instance Method Details

#decrypt(data) ⇒ Object



238
239
240
241
242
243
# File 'lib/owrb.rb', line 238

def decrypt( data )
  @cipher.decrypt
  @cipher.key = @key
  @cipher.iv = @iv
  "#{@cipher.update( data )}#{@cipher.final}"
end

#encrypt(data) ⇒ Object



231
232
233
234
235
236
# File 'lib/owrb.rb', line 231

def encrypt( data )
  @cipher.encrypt
  @cipher.key = @key
  @cipher.iv = @iv
  "#{@cipher.update( data )}#{@cipher.final}"
end

#key_iv(pass, salt, count = 2000) ⇒ Object



224
225
226
227
228
229
# File 'lib/owrb.rb', line 224

def key_iv( pass, salt, count = 2000 )
  result = OpenSSL::PKCS5.pbkdf2_hmac_sha1( pass, salt, count, @cipher.key_len + @cipher.iv_len )
  @key = result[ 0, @cipher.key_len ]
  @iv = result[ @cipher.key_len, @cipher.iv_len ]
  [ @key, @iv ]
end