class Universa::PublicKey

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

Public Class Methods

from_packed(packed, password: nil) click to toggle source

Load key from packed, optinally, using the password

@param [String] packed binary string with packed key @param [String] password optional password

# 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

Public Instance Methods

bit_strength() click to toggle source

@return key strength in bits, e.g. 2048, 4096…

# File lib/universa/keys.rb, line 67
def bit_strength
  getBitStrength()
end
encrypt(data) click to toggle source

@param [String] data binary or usual data string @return [String] binary string with encrypted data

# File lib/universa/keys.rb, line 93
def encrypt(data)
  __getobj__.encrypt(data.force_encoding('binary'))
end
long_address() click to toggle source

@return [KeyAddress] long address

# File lib/universa/keys.rb, line 77
def long_address
  @long_address ||= get_long_address()
end
short_address() click to toggle source

@return [KeyAddress] short address

# File lib/universa/keys.rb, line 72
def short_address
  @short_address ||= get_short_address()
end
verify(data, signature, hash_type = "SHA3_384") click to toggle source

Check signature

@param [String] data as binary or normal string @param [Object] signature as binary string @param [Object] hash_type to use (SHA256, SHA512, SHA3_384 and so on) @return true if it is ok

# 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