Class: Miscreant::Internals::AES::BlockCipher
- Inherits:
-
Object
- Object
- Miscreant::Internals::AES::BlockCipher
- Defined in:
- lib/miscreant/internals/aes/block_cipher.rb
Overview
The AES cipher in a raw block mode (a.k.a. ECB mode)
NOTE: The only valid use of ECB mode is constructing higher-level cryptographic primitives. This library uses this class to implement the CMAC and PMAC message authentication codes.
Instance Method Summary collapse
-
#encrypt(message) ⇒ Object
Encrypt the given AES block-sized message.
-
#initialize(key) ⇒ BlockCipher
constructor
Create a new block cipher instance.
-
#inspect ⇒ String
Inspect this AES block cipher instance.
Constructor Details
#initialize(key) ⇒ BlockCipher
Create a new block cipher instance
19 20 21 22 23 24 25 26 |
# File 'lib/miscreant/internals/aes/block_cipher.rb', line 19 def initialize(key) Util.validate_bytestring("key", key, length: [16, 32]) @cipher = OpenSSL::Cipher.new("AES-#{key.length * 8}-ECB") @cipher.encrypt @cipher.padding = 0 @cipher.key = key end |
Instance Method Details
#encrypt(message) ⇒ Object
Encrypt the given AES block-sized message
41 42 43 44 |
# File 'lib/miscreant/internals/aes/block_cipher.rb', line 41 def encrypt() Util.validate_bytestring("message", , length: Block::SIZE) @cipher.update() + @cipher.final end |
#inspect ⇒ String
Inspect this AES block cipher instance
31 32 33 |
# File 'lib/miscreant/internals/aes/block_cipher.rb', line 31 def inspect to_s end |