Class: Universa::SymmetricKey

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

Overview

A com.icodici.crypto.SymmetricKey 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_password(password, rounds, salt = nil) ⇒ SymmetricKey

Derive key from password using PBKDF2 standard

Parameters:

  • password (String)

    to derive key from

  • rounds (Object)

    derivation rounds

  • salt (Object) (defaults to: nil)

    optional salt used to disallow detect password match by key match

Returns:



108
109
110
111
# File 'lib/universa/keys.rb', line 108

def self.from_password(password, rounds, salt = nil)
  salt.force_encoding(Encoding::BINARY) if salt
  invoke_static 'fromPassword', password, rounds, salt
end

Instance Method Details

#eta_decrypt(plaintext) ⇒ Object

Decrypt data using EtA (HMAC)



136
137
138
# File 'lib/universa/keys.rb', line 136

def eta_decrypt(plaintext)
  __getobj__.eta_decrypt(plaintext.force_encoding('binary'))
end

#eta_encrypt(plaintext) ⇒ Object

Encrypt data using EtA (HMAC)



131
132
133
# File 'lib/universa/keys.rb', line 131

def eta_encrypt(plaintext)
  __getobj__.etaEncrypt(plaintext.force_encoding('binary'))
end

#keyString

Get the key as binary string

Returns:

  • (String)

    key bytes (binary string)



126
127
128
# File 'lib/universa/keys.rb', line 126

def key
  @key ||= getKey()
end

#sizeInteger

Returns size in bytes.

Returns:

  • (Integer)

    size in bytes



120
121
122
# File 'lib/universa/keys.rb', line 120

def size
  @size ||= getSize()
end

#size_in_bitsInteger

How many bits contains the key

Returns:

  • (Integer)

    size in bits



115
116
117
# File 'lib/universa/keys.rb', line 115

def size_in_bits
  @bit_strength ||= getBitStrength()
end