Method: Tokenifier::Decrypt#decrypt

Defined in:
lib/tokenifier/decrypt.rb

#decrypt(token, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tokenifier/decrypt.rb', line 16

def decrypt(token, options = {})

  raise Error, "Encrypted data should be a String" unless token.is_a?(String)
  raise Error, "Got an incomlete encrypted string" if token.size < 12

  cipher(options[:secret]) do |c|
    unpack_string(c.dec(token))
  end

rescue OpenSSL::Cipher::CipherError => e
  raise Error, "Got a malformed string"
end