lib/gibberish/aes.rb in gibberish-0.0.2 vs lib/gibberish/aes.rb in gibberish-1.0.0

- old
+ new

@@ -1,8 +1,37 @@ module Gibberish + # Handles AES encryption and decryption in a way that is compatible + # with OpenSSL. + # + # Defaults to 256-bit CBC encryption, ideally you should leave it + # this way + # + # ## Basic Usage + # + # ### Encrypting + # + # cipher = Gibberish::AES.new('p4ssw0rd') + # cipher.encrypt("some secret text") + # #=> "U2FsdGVkX1/D7z2azGmmQELbMNJV/n9T/9j2iBPy2AM=\n" + # + # ### Decrypting + # + # cipher = Gibberish::AES.new('p4ssw0rd') + # cipher.decrypt(""U2FsdGVkX1/D7z2azGmmQELbMNJV/n9T/9j2iBPy2AM=\n"") + # #=> "some secret text" + # + # ## OpenSSL Interop + # + # echo "U2FsdGVkX1/D7z2azGmmQELbMNJV/n9T/9j2iBPy2AM=\n" | openssl enc -d -aes-256-cbc -a -k p4ssw0rd + # class AES attr_reader :password, :size, :cipher + + # Initialize with the password + # + # @param [String] password + # @param [Integer] size def initialize(password, size=256) @password = password @size = size @cipher = OpenSSL::Cipher::Cipher.new("aes-#{size}-cbc") end