scinote-web/app/utilities/encryptor.rb
2016-07-21 13:11:15 +02:00

19 lines
No EOL
575 B
Ruby

module Encryptor
def decrypt(data)
return '' unless data.present?
cipher = build_cipher(:decrypt, 'f5awRubeTUd2E*8duxum')
cipher.update(Base64.urlsafe_decode64(data).unpack('m')[0]) + cipher.final
end
def encrypt(data)
return '' unless data.present?
cipher = build_cipher(:encrypt, 'f5awRubeTUd2E*8duxum')
Base64.urlsafe_encode64([cipher.update(data) + cipher.final].pack('m'))
end
def build_cipher(type, password)
cipher = OpenSSL::Cipher::Cipher.new('DES-EDE3-CBC').send(type)
cipher.pkcs5_keyivgen(password)
cipher
end
end