Class: AsymmetricKey

Inherits:
Object
  • Object
show all
Includes:
Utils::HashUtils
Defined in:
lib/crypto/asymmetric_key.rb

Overview

SignatureAlgorithm =

Ed25519: 'ed25519',
Secp256K1: 'secp256k1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::HashUtils

account_hash_from_byte_to_hex, byte_hash

Constructor Details

#initialize(public_key = CLPublicKey.new([204, 238, 25, 54, 110, 175, 3, 72, 124, 184, 17, 151, 174, 142, 220, 177, 180, 127, 33, 76, 238, 0, 214, 89, 115, 128, 9, 107, 159, 132, 99, 193], 1), private_key = nil, signature_algorithm = nil) ⇒ AsymmetricKey

Returns a new instance of AsymmetricKey.

Parameters:

  • public_key (CLPublicKey) (defaults to: CLPublicKey.new([204, 238, 25, 54, 110, 175, 3, 72, 124, 184, 17, 151, 174, 142, 220, 177, 180, 127, 33, 76, 238, 0, 214, 89, 115, 128, 9, 107, 159, 132, 99, 193], 1))
  • private_key (Array) (defaults to: nil)
  • signature_algorithm (SignatureAlgorithm) (defaults to: nil)


22
23
24
25
26
27
28
# File 'lib/crypto/asymmetric_key.rb', line 22

def initialize(public_key = CLPublicKey.new([204, 238, 25, 54, 110, 175, 3, 72, 124, 184, 17, 151, 174, 142, 220, 
177, 180, 127, 33, 76, 238, 0, 214, 89, 115, 128, 9, 107, 159, 132, 99, 193], 1), private_key = nil, signature_algorithm = nil)
  @public_key = public_key
  @private_key = private_key
  @signature_algorithm = signature_algorithm
  @tag = @public_key.get_cl_public_key_tag
end

Instance Attribute Details

#public_keyObject (readonly)

Returns the value of attribute public_key.



17
18
19
# File 'lib/crypto/asymmetric_key.rb', line 17

def public_key
  @public_key
end

#signature_algorithmObject (readonly)

Returns the value of attribute signature_algorithm.



17
18
19
# File 'lib/crypto/asymmetric_key.rb', line 17

def signature_algorithm
  @signature_algorithm
end

Instance Method Details

#account_hex(public_key) ⇒ String

Returns account_hex.

Parameters:

Returns:

  • (String)

    account_hex



48
49
50
# File 'lib/crypto/asymmetric_key.rb', line 48

def (public_key)
   = @public_key.to_hex
end

#create_from_private_key_file(path_to_private_key) ⇒ Object

Parameters:

  • path_to_private_key (String)


64
65
# File 'lib/crypto/asymmetric_key.rb', line 64

def create_from_private_key_file(path_to_private_key)
end

#export_public_key_in_pemObject

Get public key which is stored in pem



68
69
# File 'lib/crypto/asymmetric_key.rb', line 68

def export_public_key_in_pem
end

#get_public_keyCLPublicKey

Returns:



31
32
33
# File 'lib/crypto/asymmetric_key.rb', line 31

def get_public_key
  @public_key
end

#get_public_key_hexString

Get public hex-encoded string

Returns:

  • (String)


42
43
44
# File 'lib/crypto/asymmetric_key.rb', line 42

def get_public_key_hex
 "0#{@tag}" + Utils::Base16.encode16(@public_key.get_value)
end

#get_signature_algorithmObject



35
36
37
# File 'lib/crypto/asymmetric_key.rb', line 35

def get_signature_algorithm
  @signature_algorithm
end

#sign(message) ⇒ String

Parameters:

  • message (String)

Returns:

  • (String)


73
74
# File 'lib/crypto/asymmetric_key.rb', line 73

def sign(message)
end

#verify(signature, message) ⇒ Boolean

Parameters:

  • signature (String)
  • message (String)

Returns:



80
81
# File 'lib/crypto/asymmetric_key.rb', line 80

def verify(signature, message) 
end