Class: Universa::SymmetricKey
- Inherits:
-
RemoteAdapter
- Object
- Delegator
- RemoteAdapter
- Universa::SymmetricKey
- 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
-
.from_password(password, rounds, salt = nil) ⇒ SymmetricKey
Derive key from password using PBKDF2 standard.
Instance Method Summary collapse
-
#eta_decrypt(plaintext) ⇒ Object
Decrypt data using EtA (HMAC).
-
#eta_encrypt(plaintext) ⇒ Object
Encrypt data using EtA (HMAC).
-
#key ⇒ String
Get the key as binary string.
-
#size ⇒ Integer
Size in bytes.
-
#size_in_bits ⇒ Integer
How many bits contains the key.
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
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 |
#key ⇒ String
Get the key as binary string
125 126 127 |
# File 'lib/universa/keys.rb', line 125 def key @key ||= getKey() end |
#size ⇒ Integer
Returns size in bytes.
119 120 121 |
# File 'lib/universa/keys.rb', line 119 def size @size ||= getSize() end |
#size_in_bits ⇒ Integer
How many bits contains the key
114 115 116 |
# File 'lib/universa/keys.rb', line 114 def size_in_bits @bit_strength ||= getBitStrength() end |