我正在使用OpenSSL::Cipher.new('AES-256-CBC')
至encrypt
和decrypt
文件。当我在Rails控制台中的代码下运行时,它工作正常。但是,当执行作业wrong final block length
时,会在cipher.final
tmp_file
是GCS文件链接
Encrypt.generate_enc_keys
是使用lib
OpenSSL::PKCS5.pbkdf2_hmac
def generate_decrypted_agreement tmp_file
cipher = OpenSSL::Cipher.new('AES-256-CBC')
cipher.decrypt
cipher.key = Encrypt.generate_enc_keys('testkey1234', 'test', 10, 32)
cipher.iv = Encrypt.generate_enc_keys('testiv1234', 'test', 10, 16)
buf = ''
File.open("la.pdf", "wb") do |outf|
open(tmp_file) do |inf|
while inf.read(4096, buf)
outf << cipher.update(buf)
end
outf << cipher.final
end
end
结束