Module: Base64Token
- Defined in:
- lib/base64_token.rb,
lib/base64_token/version.rb
Defined Under Namespace
Classes: ConfigurationError, Error
Constant Summary
collapse
- VERSION =
'2.0.0'
Class Method Summary
collapse
Class Method Details
.encryption_key=(key) ⇒ Object
34
35
36
37
|
# File 'lib/base64_token.rb', line 34
def encryption_key=(key)
@encryption_key = key
@crypto_box = nil
end
|
.generate(**hash) ⇒ Object
14
15
16
17
18
|
# File 'lib/base64_token.rb', line 14
def generate(**hash)
json = JSON.generate(hash)
cipher = encrypt(json)
Base64.urlsafe_encode64(cipher)
end
|
.generate_key ⇒ Object
28
29
30
31
32
|
# File 'lib/base64_token.rb', line 28
def generate_key
Base64.strict_encode64(
RbNaCl::Random.random_bytes(RbNaCl::SecretBox.key_bytes)
)
end
|
.parse(token) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/base64_token.rb', line 20
def parse(token)
return {} if !token || token.strip.empty?
cipher = base64_decode(token)
json = decrypt(cipher)
JSON.parse(json).transform_keys(&:to_sym)
end
|