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:



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

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)



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

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

#eta_encrypt(plaintext) ⇒ Object

Encrypt data using EtA (HMAC)



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

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

#keyString

Get the key as binary string

Returns:

  • (String)

    key bytes (binary string)



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

def key
  @key ||= getKey()
end

#sizeInteger

Returns size in bytes.

Returns:

  • (Integer)

    size in bytes



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

def size
  @size ||= getSize()
end

#size_in_bitsInteger

How many bits contains the key

Returns:

  • (Integer)

    size in bits



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

def size_in_bits
  @bit_strength ||= getBitStrength()
end