Ruby China

新手问题 warning: constant OpenSSL::Cipher::Cipher is deprecated

sevk · 2018年11月16日 · 最后由 sevk 回复于 2018年11月26日 · 4206 次阅读

这个警告如何去掉? 可以用别的什么库吗?

#!/usr/bin/env ruby 
require 'openssl'
# AES-128 ECB mode test vectors
KEY = ["2b7e151628aed2a6abf7158809cf4f3c"].pack("H*")
PLAINTEXT = ["6bc1bee22e409f96e93d7e117393172a"].pack("H*")
CIPHERTEXT = ["3ad77bb40d7a3660a89ecaf32466ef97"].pack("H*")
cipher = OpenSSL::Cipher::Cipher.new("aes-128-ecb")
cipher.key = KEY
cipher.padding = 0 # Padding is enabled by default o_O
puts "test encry: "
cipher.encrypt
ciphertext = cipher.update(PLAINTEXT) << cipher.final
if ciphertext == CIPHERTEXT
 puts "OK!"
else
 puts "FAILED!"
end
puts "test decry: "
cipher.reset
cipher.decrypt
plaintext = cipher.update(CIPHERTEXT) << cipher.final
if plaintext == PLAINTEXT
 puts "OK!"
else
 puts "FAILED!"
end
ecb1.rb:9: warning: constant OpenSSL::Cipher::Cipher is deprecated

直接使用 OpenSSL::Cipher 这个类就好了

so_zengtao 回复

原来这么简单啊,你是怎么找到答案的? 👍

sevk 回复

花了 10 秒钟看了一下文档 ... 😂

This class is only provided for backwards compatibility. Use OpenSSL::Cipher

so_zengtao 回复

哦谢谢,我用 pry 的 show-doc OpenSSL::Cipher::Cipher,没显示。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号

AltStyle によって変換されたページ (->オリジナル) /