Class: Keyring::Encryptor::AES::Base
- Inherits:
-
Object
- Object
- Keyring::Encryptor::AES::Base
show all
- Defined in:
- lib/keyring/encryptor/aes.rb
Class Method Summary
collapse
Class Method Details
.build_cipher ⇒ Object
5
6
7
|
# File 'lib/keyring/encryptor/aes.rb', line 5
def self.build_cipher
OpenSSL::Cipher.new(cipher_name)
end
|
.decrypt(key, message) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/keyring/encryptor/aes.rb', line 24
def self.decrypt(key, message)
cipher = build_cipher
cipher.decrypt
message = Base64.strict_decode64(message)
iv = message[0...cipher.iv_len]
encrypted = message[cipher.iv_len..-1]
cipher.iv = iv
cipher.key = key
cipher.update(encrypted) + cipher.final
end
|
.encrypt(key, message) ⇒ Object
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/keyring/encryptor/aes.rb', line 13
def self.encrypt(key, message)
cipher = build_cipher
cipher.encrypt
iv = cipher.random_iv
cipher.iv = iv
cipher.key = key
encrypted = cipher.update(message) + cipher.final
Base64.strict_encode64("#{iv}#{encrypted}")
end
|
.key_size ⇒ Object
9
10
11
|
# File 'lib/keyring/encryptor/aes.rb', line 9
def self.key_size
@key_size ||= build_cipher.key_len
end
|