lib/gibberish/aes.rb in gibberish-1.2.0 vs lib/gibberish/aes.rb in gibberish-1.2.1
- old
+ new
@@ -36,11 +36,11 @@
@size = size
@cipher = OpenSSL::Cipher::Cipher.new("aes-#{size}-cbc")
end
def encrypt(data, opts={})
- salt = generate_salt
+ salt = generate_salt(opts[:salt])
setup_cipher(:encrypt, salt)
e = cipher.update(data) + cipher.final
e = "Salted__#{salt}#{e}" #OpenSSL compatible
opts[:binary] ? e : Base64.encode64(e)
end
@@ -57,10 +57,13 @@
alias :dec :decrypt
alias :d :decrypt
private
- def generate_salt
+ def generate_salt(supplied_salt)
+ if supplied_salt
+ return supplied_salt.to_s[0,8].ljust(8,'.')
+ end
s = ''
8.times {s << rand(255).chr}
s
end