Class: Owrb::Data::Cipher
- Inherits:
-
Object
- Object
- Owrb::Data::Cipher
- Defined in:
- lib/owrb.rb
Instance Attribute Summary collapse
-
#cipher ⇒ Object
readonly
Returns the value of attribute cipher.
-
#iv ⇒ Object
Returns the value of attribute iv.
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
- #decrypt(data) ⇒ Object
- #encrypt(data) ⇒ Object
-
#initialize(cipher) ⇒ Cipher
constructor
A new instance of Cipher.
- #key_iv(pass, salt, count = 2000) ⇒ Object
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
#cipher ⇒ Object (readonly)
Returns the value of attribute cipher.
215 216 217 |
# File 'lib/owrb.rb', line 215 def cipher @cipher end |
#iv ⇒ Object
Returns the value of attribute iv.
216 217 218 |
# File 'lib/owrb.rb', line 216 def iv @iv end |
#key ⇒ Object
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 |