mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-27 18:52:07 +08:00
19 lines
No EOL
575 B
Ruby
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 |