开发者

TypeError: wrong argument (String)! (Expected kind of OpenSSL::Digest::Digest)

I have a problem with Ruby's openssl library.

Here is what I do:

In my Rails application, I start the "./script/console", then type:

>>OpenSSL::HMAC.hexdigest('sha256','','')

gives me this error:

TypeError: wrong argument 开发者_如何学运维(String)! (Expected kind of OpenSSL::Digest::Digest) from (irb):15:in `hexdigest' from (irb):15

I googled this error but couldn't get an answer on what's going on.


The error message says you gave a string where an object of kind OpenSSL::Digest::Digest was expected.

So use OpenSSL::Digest::SHA256.new (which is an object of kind OpenSSL::Digest::Digest on account of SHA256 being a subclass of Digest) instead of 'sha256' (which is a string).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜