module EncryptedId
Constants
- CIPHER_IV
- CIPHER_NAME
- VERSION
Public Class Methods
decrypt(key, id)
click to toggle source
# File lib/encrypted_id.rb, line 18 def self.decrypt(key, id) c = OpenSSL::Cipher::Cipher.new(CIPHER_NAME).decrypt c.iv = CIPHER_IV c.key = key c.update([id].pack('H*')) + c.final end
encrypt(key, id)
click to toggle source
# File lib/encrypted_id.rb, line 25 def self.encrypt(key, id) c = OpenSSL::Cipher::Cipher.new(CIPHER_NAME).encrypt c.iv = CIPHER_IV c.key = key (c.update("#{id}") + c.final).unpack('H*')[0] end
Public Instance Methods
encrypted_id(options = {})
click to toggle source
# File lib/encrypted_id.rb, line 10 def encrypted_id(options = {}) extend ClassMethods include InstanceMethods cattr_accessor :encrypted_id_key self.encrypted_id_key = Digest::SHA256.digest(options[:key] || encrypted_id_default_key) self.define_singleton_method(:find_single, lambda { puts "foo" }) end