Class: Passkit::UrlEncrypt

Inherits:
Object
  • Object
show all
Defined in:
lib/passkit/url_encrypt.rb,
sig/lib/passkit/url_encrypt.rbs

Class Method Summary collapse

Class Method Details

.decrypt(string) ⇒ Hash[Symbol, untyped]

Parameters:

  • string (String)

Returns:

  • (Hash[Symbol, untyped])


13
14
15
16
17
18
19
# File 'lib/passkit/url_encrypt.rb', line 13

def decrypt(string)
  cipher = cypher.decrypt
  cipher.key = encryption_key
  s = [string].pack("H*").unpack("C*").pack("c*")

  JSON.parse(cipher.update(s) + cipher.final, symbolize_names: true)
end

.encrypt(payload) ⇒ String

Parameters:

  • payload (Hash[untyped, untyped])

Returns:

  • (String)


4
5
6
7
8
9
10
11
# File 'lib/passkit/url_encrypt.rb', line 4

def encrypt(payload)
  string = payload.to_json
  cipher = cypher.encrypt
  cipher.key = encryption_key
  s = cipher.update(string) + cipher.final

  s.unpack1("H*").upcase
end