class TarvitHelpers::SimpleCrypt
Constants
- TYPE
Public Class Methods
new(secret_key)
click to toggle source
# File lib/tarvit-helpers/modules/simple_crypt.rb, line 9 def initialize(secret_key) @ciper = OpenSSL::Cipher::Cipher.new(TYPE) @secret_key = secret_key.to_s end
Public Instance Methods
decrypt(code)
click to toggle source
# File lib/tarvit-helpers/modules/simple_crypt.rb, line 22 def decrypt(code) hash = Base64.decode64(code) @ciper.decrypt @ciper.key = Digest::SHA1.hexdigest(@secret_key) d = @ciper.update(hash) d << @ciper.final end
encrypt(string)
click to toggle source
# File lib/tarvit-helpers/modules/simple_crypt.rb, line 14 def encrypt(string) @ciper.encrypt @ciper.key = Digest::SHA1.hexdigest(@secret_key) res = @ciper.update(string) res << @ciper.final Base64.encode64(res) end