| Module | AesShared |
| In: |
lib/ruby-aes/aes_shared.rb
|
# File lib/ruby-aes/aes_shared.rb, line 23
23: def decrypt_blocks(buffer)
24: raise "Bad block length" unless (buffer.length % 16).zero?
25: pt = ""
26: block = ""
27: buffer.each_byte do |char|
28: block << char
29: if block.length == 16
30: pt << decrypt_block(block)
31: block = ""
32: end
33: end
34: pt
35: end
# File lib/ruby-aes/aes_shared.rb, line 55
55: def decrypt_buffer(buffer)
56: pt = ""
57: block = ""
58: buffer.each_byte do |char|
59: block << char
60: if block.length == 16
61: pt << decrypt_block(block)
62: block = ""
63: end
64: end
65: if block.length != 1
66: raise 'Bad Block Padding'
67: elsif (c = block[-1]).zero?
68: pt
69: else
70: if block * c == pt[-c..-1]
71: pt[0..-c-1]
72: else
73: raise "Bad Block Padding"
74: end
75: end
76: end
# File lib/ruby-aes/aes_shared.rb, line 9
9: def encrypt_blocks(buffer)
10: raise "Bad block length" unless (buffer.length % 16).zero?
11: ct = ""
12: block = ""
13: buffer.each_byte do |char|
14: block << char
15: if block.length == 16
16: ct << encrypt_block(block)
17: block = ""
18: end
19: end
20: ct
21: end
# File lib/ruby-aes/aes_shared.rb, line 37
37: def encrypt_buffer(buffer)
38: ct = ""
39: block = ""
40: buffer.each_byte do |char|
41: block << char
42: if block.length == 16
43: ct << encrypt_block(block)
44: block = ""
45: end
46: end
47: c = "\000"
48: if (m = 16 - block.length % 16) != 16
49: c = m.chr
50: ct << encrypt_block(block << c * m)
51: end
52: ct << c
53: end