Module: EncryptedId
- Defined in:
- lib/encrypted_id.rb,
lib/encrypted_id/version.rb
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Constant Summary
collapse
- CIPHER_NAME =
'aes-256-cbc'
- CIPHER_IV =
['1e5673b2572af26a8364a50af84c7d2a'].pack('H*')
- VERSION =
'1.1.1'
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.decrypt(key, id) ⇒ Object
18
19
20
21
22
23
|
# 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) ⇒ Object
25
26
27
28
29
30
|
# 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
|
Instance Method Details
#encrypted_id(options = {}) ⇒ Object
10
11
12
13
14
15
16
|
# 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
|