lib/lockbox/encryptor.rb in lockbox-0.3.1 vs lib/lockbox/encryptor.rb in lockbox-0.3.2
- old
+ new
@@ -1,21 +1,25 @@
module Lockbox
class Encryptor
def initialize(**options)
options = Lockbox.default_options.merge(options)
+ @encode = options.delete(:encode)
previous_versions = options.delete(:previous_versions)
@boxes =
[Box.new(**options)] +
Array(previous_versions).map { |v| Box.new(key: options[:key], **v) }
end
def encrypt(message, **options)
message = check_string(message, "message")
- @boxes.first.encrypt(message, **options)
+ ciphertext = @boxes.first.encrypt(message, **options)
+ ciphertext = Base64.strict_encode64(ciphertext) if @encode
+ ciphertext
end
def decrypt(ciphertext, **options)
+ ciphertext = Base64.decode64(ciphertext) if @encode
ciphertext = check_string(ciphertext, "ciphertext")
# ensure binary
if ciphertext.encoding != Encoding::BINARY
# dup to prevent mutation