Class: Ciphers::Aes

Inherits:
Object
  • Object
show all
Defined in:
lib/crypto-toolbox/ciphers/aes.rb

Instance Method Summary collapse

Constructor Details

#initialize(key_size: 128) ⇒ Aes

Returns a new instance of Aes.



5
6
7
8
9
# File 'lib/crypto-toolbox/ciphers/aes.rb', line 5

def initialize(key_size: 128)
  @key_size = key_size
  @block_size_bits  = 128
  @block_size_bytes = 16
end

Instance Method Details

#decipher_cbc(key_str, input_str, iv: nil, strip_padding: true) ⇒ Object



25
26
27
28
# File 'lib/crypto-toolbox/ciphers/aes.rb', line 25

def decipher_cbc(key_str,input_str,iv: nil,strip_padding: true)
  plain = unicipher_cbc(:decipher,key_str,CryptBuffer(input_str),iv).to_crypt_buffer
  strip_padding ? plain.strip_padding : plain
end

#decipher_ecb(key, input, strip_padding: true) ⇒ Object

NOTE convert ECB encryption to AES gem or both to openssl



12
13
14
15
# File 'lib/crypto-toolbox/ciphers/aes.rb', line 12

def decipher_ecb(key,input,strip_padding: true)
  plain = decipher_ecb_blockwise(CryptBuffer(key),CryptBuffer(input).chunks_of(@block_size_bytes)).to_crypt_buffer
  strip_padding ? plain.strip_padding : plain
end

#encipher_cbc(key_str, input_str, iv: nil) ⇒ Object



21
22
23
# File 'lib/crypto-toolbox/ciphers/aes.rb', line 21

def encipher_cbc(key_str,input_str,iv: nil)
  unicipher_cbc(:encipher,key_str,pad_message(input_str),iv)
end

#encipher_ecb(key, input) ⇒ Object



17
18
19
# File 'lib/crypto-toolbox/ciphers/aes.rb', line 17

def encipher_ecb(key,input)
  encipher_ecb_blockwise(CryptBuffer(key),pad_message(input).chunks_of(@block_size_bytes))
end