Created
January 29, 2015 16:04
-
-
Save guivinicius/6888adaf30924621c4ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EncDec | |
KEY = "FA 0E 3C 9B 4F A2 C7 AA 37 0F CA 9B 5A 91 64 08" | |
IV = "AA AD 8B 4C 00 E1 3F 53 B8 E7 16 BC B5 F4 D1 B9" | |
attr_reader :cipher, :message, :key, :iv | |
def initialize(message, key = nil, iv = nil) | |
@key, @iv = key, iv | |
@cipher = OpenSSL::Cipher::AES128.new(:CBC) | |
@message = message | |
cipher.key = key || KEY.delete(' ') | |
cipher.iv = iv || IV.delete(' ') | |
end | |
def decrypt | |
cipher.decrypt | |
cipher.update(message) + cipher.final | |
end | |
def encrypt | |
cipher.encrypt | |
cipher.update(message) + cipher.final | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment