简体   繁体   English

openssl ruby​​ 1.9.3和nodejs

[英]openssl ruby 1.9.3 and nodejs

In nodejs I can use crypto to do these function: 在nodejs中,我可以使用crypto来执行以下功能:

var equal = function(value, tag) {
var expected = crypto.createHash('sha1').update(value).digest('hex'),
  actual    = crypto.createHash('sha1').update(tag).digest('hex');
 return expected === actual;

} }

How can I do the same using ruby 1.9.3 openssl library or any other library? 如何使用ruby 1.9.3 openssl库或任何其他库来做同样的事情?

You can do this with the OpenSSL bindings like this: 您可以使用如下的OpenSSL绑定来做到这一点:

require 'openssl'
digest = OpenSSL::Digest::SHA1.new
hex_digest = digest.update("value").hexdigest

You can also use the digest/sha1 library (if you're on a Ruby runtime that doesn't support the OpenSSL bindings or you just don't want to use them) 您还可以使用digest / sha1库(如果您使用的是不支持OpenSSL绑定的Ruby运行时,或者只是不想使用它们)

require 'digest/sha1'
digest = Digest::SHA1.new
hex_digest = digest.update("value").hexdigest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM