lib/rmega/crypto/aes_cbc.rb in rmega-0.2.2 vs lib/rmega/crypto/aes_cbc.rb in rmega-0.2.4
- old
+ new
@@ -26,21 +26,24 @@
cipher.encrypt
cipher.padding = 0
cipher.iv = iv if iv
cipher.key = key
- n = 0
- mac = nil
+ # n = 0
+ # mac = nil
- loop do
- block = data[n..n+15]
- break if !block or block.empty?
- block << "\x0"*(16-block.size) if block.size < 16
- n += 16
- mac = cipher.update(block)
- end
+ # loop do
+ # block = data[n..n+15]
+ # break if !block or block.empty?
+ # block << "\x0"*(16-block.size) if block.size < 16
+ # n += 16
+ # mac = cipher.update(block)
+ # end
- return mac
+ # return mac
+
+ block = data + "\x0" * ((16 - data.bytesize % 16) % 16)
+ return cipher.update(block)[-16..-1]
end
end
end
end