Class: Paseto::V2::Public::SecretKey
- Inherits:
-
Object
- Object
- Paseto::V2::Public::SecretKey
- Includes:
- Encoder
- Defined in:
- lib/paseto/public.rb
Overview
secret-key used for signing and verifying
Class Method Summary collapse
Instance Method Summary collapse
- #encode64 ⇒ Object
- #encode_hex ⇒ Object
-
#initialize(key) ⇒ SecretKey
constructor
A new instance of SecretKey.
- #public_key ⇒ Object
- #sign(message, footer = EMPTY_FOOTER) ⇒ Object
- #verify(message, footer = nil) ⇒ Object
Constructor Details
#initialize(key) ⇒ SecretKey
Returns a new instance of SecretKey.
36 37 38 39 |
# File 'lib/paseto/public.rb', line 36 def initialize(key) @key = key @nacl = RbNaCl::SigningKey.new(key) end |
Class Method Details
.decode64(encoded_key) ⇒ Object
28 29 30 |
# File 'lib/paseto/public.rb', line 28 def self.decode64(encoded_key) new(Paseto.decode64(encoded_key)) end |
.decode_hex(encoded_key) ⇒ Object
32 33 34 |
# File 'lib/paseto/public.rb', line 32 def self.decode_hex(encoded_key) new(Paseto.decode_hex(encoded_key)) end |
.generate ⇒ Object
24 25 26 |
# File 'lib/paseto/public.rb', line 24 def self.generate new(RbNaCl::SigningKey.generate.to_bytes) end |
Instance Method Details
#encode64 ⇒ Object
57 58 59 |
# File 'lib/paseto/public.rb', line 57 def encode64 Paseto.encode64(@key) end |
#encode_hex ⇒ Object
61 62 63 |
# File 'lib/paseto/public.rb', line 61 def encode_hex Paseto.encode_hex(@key) end |
#public_key ⇒ Object
53 54 55 |
# File 'lib/paseto/public.rb', line 53 def public_key PublicKey.new(@nacl.verify_key.to_bytes) end |
#sign(message, footer = EMPTY_FOOTER) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/paseto/public.rb', line 41 def sign(, = EMPTY_FOOTER) data = (, ) # Sign a message with the signing key signature = @nacl.sign(data) Paseto::Token.new(HEADER, + signature, ). end |
#verify(message, footer = nil) ⇒ Object
49 50 51 |
# File 'lib/paseto/public.rb', line 49 def verify(, = nil) public_key.verify(, ) end |