Class: Tem::Keys::Symmetric
Overview
Wraps a TEM symmetric key, e.g. an AES key.
Constant Summary
collapse
- @@cipher_mode =
'ECB'
Instance Attribute Summary
Attributes inherited from Tem::Key
#ssl_key
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Tem::Key
new_from_ssl_key, #to_tem_key
Constructor Details
#initialize(ssl_key) ⇒ Symmetric
Creates a new symmetric key based on an OpenSSL Cipher instance, augmented with a key accessor.
17
18
19
20
21
|
# File 'lib/tem/keys/symmetric.rb', line 17
def initialize(ssl_key)
super ssl_key
@key = ssl_key.key
@cipher_class = ssl_key.class
end
|
Class Method Details
.generate ⇒ Object
Generates a new symmetric key.
9
10
11
12
13
|
# File 'lib/tem/keys/symmetric.rb', line 9
def self.generate
cipher = OpenSSL::Cipher::AES128.new @@cipher_mode
key = cipher.random_key
self.new key
end
|
Instance Method Details
#decrypt(data) ⇒ Object
36
37
38
|
# File 'lib/tem/keys/symmetric.rb', line 36
def decrypt(data)
cipher.encrypt_or_decrypt data, false
end
|
#encrypt(data) ⇒ Object
32
33
34
|
# File 'lib/tem/keys/symmetric.rb', line 32
def encrypt(data)
cipher.encrypt_or_decrypt data, true
end
|
#encrypt_or_decrypt(data, do_encrypt) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/tem/keys/symmetric.rb', line 24
def encrypt_or_decrypt(data, do_encrypt)
cipher = @cipher_class.new @@cipher_mode
do_encrypt ? cipher.encrypt : cipher.decrypt
cipher.key = @key
cipher.iv = "\0" * 16
end
|
#sign(data) ⇒ Object
40
41
|
# File 'lib/tem/keys/symmetric.rb', line 40
def sign(data)
end
|
#verify(data) ⇒ Object
43
44
|
# File 'lib/tem/keys/symmetric.rb', line 43
def verify(data)
end
|