Ruby OpenSSL :: Cipher :: CipherError:错误的最终块长度

时间:2019-02-26 11:21:22

标签: openssl ruby-on-rails-5.1 ruby-2.4

我正在使用OpenSSL::Cipher.new('AES-256-CBC')encryptdecrypt文件。当我在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

结束

0 个答案:

没有答案