Class: Universa::PublicKey
- Inherits:
-
RemoteAdapter
- Object
- Delegator
- RemoteAdapter
- Universa::PublicKey
- 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
-
.from_packed(packed, password: nil) ⇒ Object
Load key from packed, optinally, using the password.
Instance Method Summary collapse
-
#bit_strength ⇒ Object
Key strength in bits, e.g.
-
#encrypt(data) ⇒ String
Binary string with encrypted data.
-
#long_address ⇒ KeyAddress
Long address.
-
#short_address ⇒ KeyAddress
Short address.
-
#verify(data, signature, hash_type = "SHA3_384") ⇒ Object
Check signature.
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
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_strength ⇒ Object
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.
93 94 95 |
# File 'lib/universa/keys.rb', line 93 def encrypt(data) __getobj__.encrypt(data.force_encoding('binary')) end |
#long_address ⇒ KeyAddress
Returns long address.
77 78 79 |
# File 'lib/universa/keys.rb', line 77 def long_address @long_address ||= get_long_address() end |
#short_address ⇒ KeyAddress
Returns short address.
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
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 |