Class: Paseto::V2::Public::SecretKey

Inherits:
Object
  • Object
show all
Includes:
Encoder
Defined in:
lib/paseto/public.rb

Overview

secret-key used for signing and verifying

Class Method Summary collapse

Instance Method Summary collapse

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

.generateObject



24
25
26
# File 'lib/paseto/public.rb', line 24

def self.generate
  new(RbNaCl::SigningKey.generate.to_bytes)
end

Instance Method Details

#encode64Object



57
58
59
# File 'lib/paseto/public.rb', line 57

def encode64
  Paseto.encode64(@key)
end

#encode_hexObject



61
62
63
# File 'lib/paseto/public.rb', line 61

def encode_hex
  Paseto.encode_hex(@key)
end

#public_keyObject



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(message, footer = EMPTY_FOOTER)
  data = encode_message(message, footer)
  # Sign a message with the signing key
  signature = @nacl.sign(data)

  Paseto::Token.new(HEADER, message + signature, footer).to_message
end

#verify(message, footer = nil) ⇒ Object



49
50
51
# File 'lib/paseto/public.rb', line 49

def verify(message, footer = nil)
  public_key.verify(message, footer)
end