class Encrypt
Public Class Methods
new(pass_phrase)
click to toggle source
# 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
Public Instance Methods
decrypt(encrypted)
click to toggle source
# 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)
click to toggle source
# 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