红宝石中的错误解密错误 [英] bad decrypt error in ruby
本文介绍了红宝石中的错误解密错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在执行cipher.final
时,显示bad decrypt
错误.我试图找出问题所在.但是,我找不到.您能告诉我代码有什么问题吗?
While executing the cipher.final
, It says bad decrypt
error. I tried to find out the problem.But,I can't find . Can you tell what is wrong with my code?
这是我的代码:
require 'openssl'
require 'base64'
require 'hex_string'
result_h ="4fcd6b1ac843a2f8bf13f2e53dd5c1544fcd6b1ac843a2f8"
key = result_h.to_byte_string
encrypt_str="79994A6EF73DA76C";
cipher = OpenSSL::Cipher.new("DES-EDE3-CBC")
cipher.decrypt
cipher.key = key
data = encrypt_str.to_byte_string
res = cipher.update( data )
res << cipher.final
result_h= res.unpack("H*")[0]
puts result_h.inspect;
错误是:
in `final': bad decrypt (OpenSSL::Cipher::CipherError)
推荐答案
我遇到了类似的问题.在特定示例中:
I had a similar problem. In the specific example:
require 'openssl'
require 'base64'
require 'hex_string'
result_h ="4fcd6b1ac843a2f8bf13f2e53dd5c1544fcd6b1ac843a2f8"
key = result_h.to_byte_string
encrypt_str="79994A6EF73DA76C";
cipher = OpenSSL::Cipher.new("DES-EDE3-CBC")
cipher.decrypt
cipher.padding = 0
cipher.key = key
data = encrypt_str.to_byte_string
res = cipher.update( data )
res << cipher.final
result_h= res.unpack("H*")[0]
puts result_h.inspect;
=> "0befe932733d76e6"
如果您添加cipher.padding = 0,则会得到结果.
If you add cipher.padding = 0 it gives you a result.
这篇关于红宝石中的错误解密错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文