Class: Nis::Keypair

Inherits:
Object
  • Object
show all
Defined in:
lib/nis/keypair.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(private_key, public_key: nil) ⇒ Keypair

Returns a new instance of Keypair.

Parameters:

  • Hex (String)

    Private Key

  • options (Hash)

    a customizable set of options



7
8
9
10
# File 'lib/nis/keypair.rb', line 7

def initialize(private_key, public_key: nil)
  @private = private_key
  @public  = public_key || calc_public_key
end

Instance Attribute Details

#privateObject (readonly)

Returns the value of attribute private.



3
4
5
# File 'lib/nis/keypair.rb', line 3

def private
  @private
end

#publicObject (readonly)

Returns the value of attribute public.



3
4
5
# File 'lib/nis/keypair.rb', line 3

def public
  @public
end

Instance Method Details

#sign(data) ⇒ String

Returns Signed hex string.

Parameters:

  • Hex (String)

    string

Returns:

  • (String)

    Signed hex string



14
15
16
17
18
# File 'lib/nis/keypair.rb', line 14

def sign(data)
  bin_data = Nis::Util::Convert.hex2bin(data)
  bin_signed = Nis::Util::Ed25519.signature_hash_unsafe(bin_data, bin_secret, bin_public)
  bin_signed.unpack('H*').first
end