Class: Universa::PublicKey

Inherits:
RemoteAdapter show all
Defined in:
lib/universa/keys.rb

Overview

A com.icodici.crypto.PublicKey extension. As the key is immutable, caching is used to avoid unnecessary UMI calls.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RemoteAdapter

#__getobj__, #__setobj__, #initialize, #inspect, invoke_static, remote_class, remote_class_name, remote_field, static_method, #to_s

Constructor Details

This class inherits a constructor from Universa::RemoteAdapter

Class Method Details

.from_packed(packed, password: nil) ⇒ Object

Load key from packed, optinally, using the password

Parameters:

  • packed (String)

    binary string with packed key

  • password (String) (defaults to: nil)

    optional password



57
58
59
60
61
62
63
64
# File 'lib/universa/keys.rb', line 57

def self.from_packed(packed, password: nil)
  packed.force_encoding 'binary'
  if password
    invoke_static "unpackWithPassword", packed, password
  else
    PublicKey.new packed
  end
end

Instance Method Details

#bit_strengthObject

Returns key strength in bits, e.g. 2048, 4096…

Returns:

  • key strength in bits, e.g. 2048, 4096…



67
68
69
# File 'lib/universa/keys.rb', line 67

def bit_strength
  getBitStrength()
end

#encrypt(data) ⇒ String

Returns binary string with encrypted data.

Parameters:

  • data (String)

    binary or usual data string

Returns:

  • (String)

    binary string with encrypted data



93
94
95
# File 'lib/universa/keys.rb', line 93

def encrypt(data)
  __getobj__.encrypt(data.force_encoding('binary'))
end

#long_addressKeyAddress

Returns long address.

Returns:



77
78
79
# File 'lib/universa/keys.rb', line 77

def long_address
  @long_address ||= get_long_address()
end

#short_addressKeyAddress

Returns short address.

Returns:



72
73
74
# File 'lib/universa/keys.rb', line 72

def short_address
  @short_address ||= get_short_address()
end

#verify(data, signature, hash_type = "SHA3_384") ⇒ Object

Check signature

Parameters:

  • data (String)

    as binary or normal string

  • signature (Object)

    as binary string

  • hash_type (Object) (defaults to: "SHA3_384")

    to use (SHA256, SHA512, SHA3_384 and so on)

Returns:

  • true if it is ok



87
88
89
# File 'lib/universa/keys.rb', line 87

def verify(data, signature, hash_type = "SHA3_384")
  __getobj__.verify(data.force_encoding('binary'), signature.force_encoding('binary'), hash_type)
end