[Question] How to open and decode a string line by line when it was before encrypted
Piioo opened this issue · comments
Environment
Provide at least:
- ruby 2.7.6p219
- symmetric-encryption (4.5.0)
- Rails 6
Expected Behavior
When I encrypt a string with SymmetricEncryption.encrypt
then it should be decrypted by SymmetricEncryption::Reader.open
line by line too.
https://encryption.rocketjob.io/ -> Large File Encryption
Actual Behavior
This code is not working, when I only pass the encrypted string into the open
method
foo = SymmetricEncryption.encrypt('foo', random_iv: false, compress: false, type: :string)
foo = StringIO.new(foo)
SymmetricEncryption::Reader.open(foo) do |file|
file.each_line do |line|
puts '###############'
puts line
end
end
# OpenSSL::Cipher::CipherError: bad decrypt
But it works when I Base64.decode64
the string before. But does the line by line have any sense in large files, when we have first to decode64 it?
foo = SymmetricEncryption.encrypt('foo', random_iv: false, compress: false, type: :string)
foo = StringIO.new(Base64.decode64(foo))
SymmetricEncryption::Reader.open(foo) do |file|
file.each_line do |line|
puts '###############'
puts line
end
end
# ###############
# foo