加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby中的解密错误

发布时间:2020-12-17 03:47:05 所属栏目:百科 来源:网络整理
导读:在执行cipher.final时,它表示解密错误.我试图找出问题.但是,我找不到.你能告诉我的代码有什么问题吗? 这是我的代码: require 'openssl'require 'base64'require 'hex_string' result_h ="4fcd6b1ac843a2f8bf13f2e53dd5c1544fcd6b1ac843a2f8" key = result_
在执行cipher.final时,它表示解密错误.我试图找出问题.但是,我找不到.你能告诉我的代码有什么问题吗?

这是我的代码:

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)

解决方法

我遇到了类似的问题.在具体示例中:

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,它会给你一个结果.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读