Class: Encrypt
- Inherits:
-
Object
- Object
- Encrypt
- Defined in:
- lib/vimamsa/encrypt.rb
Instance Method Summary collapse
- #decrypt(encrypted) ⇒ Object
- #encrypt(text) ⇒ Object
-
#initialize(pass_phrase) ⇒ Encrypt
constructor
A new instance of Encrypt.
Constructor Details
#initialize(pass_phrase) ⇒ Encrypt
Returns a new instance of Encrypt.
5 6 7 8 9 10 11 12 13 |
# File 'lib/vimamsa/encrypt.rb', line 5 def initialize(pass_phrase) salt = "uvgixEtU" @enc = OpenSSL::Cipher.new "AES-128-CBC" @enc.encrypt @enc.pkcs5_keyivgen pass_phrase, salt @dec = OpenSSL::Cipher.new "AES-128-CBC" @dec.decrypt @dec.pkcs5_keyivgen pass_phrase, salt end |
Instance Method Details
#decrypt(encrypted) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/vimamsa/encrypt.rb', line 24 def decrypt(encrypted) cipher=@dec encrypted = [encrypted].pack("H*").unpack("C*").pack("c*") plain = cipher.update encrypted plain << cipher.final plain.force_encoding("utf-8") @dec.reset return plain end |
#encrypt(text) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/vimamsa/encrypt.rb', line 15 def encrypt(text) cipher=@enc encrypted = cipher.update text encrypted << cipher.final encrypted = encrypted.unpack('H*')[0].upcase @enc.reset return encrypted end |