Module: AES
- Defined in:
- lib/aes/aes.rb
Defined Under Namespace
Classes: AES
Class Method Summary collapse
-
.decrypt(cipher_text, key, opts = {}) ⇒ Object
Decrypts the cipher_text with the provided key.
-
.encrypt(plain_text, key, opts = {}) ⇒ Object
Encrypts the plain_text with the provided key.
-
.iv(format = :plain) ⇒ Object
Generates a random iv Default format is :plain.
-
.key(length = 256, format = :plain) ⇒ Object
Generates a random key of the specified length in bits Default format is :plain.
Class Method Details
.decrypt(cipher_text, key, opts = {}) ⇒ Object
Decrypts the cipher_text with the provided key
8 9 10 |
# File 'lib/aes/aes.rb', line 8 def decrypt(cipher_text, key, opts={}) ::AES::AES.new(key, opts).decrypt(cipher_text) end |
.encrypt(plain_text, key, opts = {}) ⇒ Object
Encrypts the plain_text with the provided key
4 5 6 |
# File 'lib/aes/aes.rb', line 4 def encrypt(plain_text, key, opts={}) ::AES::AES.new(key, opts).encrypt(plain_text) end |
.iv(format = :plain) ⇒ Object
Generates a random iv Default format is :plain
24 25 26 27 28 29 30 31 32 |
# File 'lib/aes/aes.rb', line 24 def iv(format=:plain) iv = ::AES::AES.new("").random_iv case format when :base_64 Base64.encode64(iv).chomp else iv end end |
.key(length = 256, format = :plain) ⇒ Object
Generates a random key of the specified length in bits Default format is :plain
13 14 15 16 17 18 19 20 21 |
# File 'lib/aes/aes.rb', line 13 def key(length=256,format=:plain) key = ::AES::AES.new("").random_key(length) case format when :base_64 Base64.encode64(key).chomp else key end end |