当我在 linux 命令行执行 openssl 命令时:
echo -n "aaaaaa" | /usr/bin/openssl dgst -sha1 -sign myprivatekey.pem | /usr/bin/openssl enc -base64 -A
我得到这个结果:
2GmJqeVDbGFsaJjMKcjW4JhPYBdI7mSwNYKrmdHtM2xpWVVSdhXc0d3zidF790mz9n9nb2yX+jMZpzNNd8xAx/WeSRxnYCg0Y/TXoMG4ynbCnttpzxrN08TJNggLOz0fWbzfMQZbHy+WghU8SlOhQExngtH8yvtE71060C/KKtI=
通过运行这个 ruby 脚本:
require 'openssl'
require 'base64'
pkey = OpenSSL::PKey::RSA.new(File.read("myprivatekey.pem"))
plaintext = OpenSSL::Digest::SHA1.new("aaaaaa").digest
enc = pkey.private_encrypt(plaintext)
puts Base64.encode64(enc)
结果不一样:
rHdXk0itL88vrz84QvCpRHM7J1w/B+Jaoo7n3fQ1D0UiPYQ4jClLQcO3iQLVifq/jMXBYvPLzQVZa/J9D7gjOwKYkKlu5c18HV8U4h0jXM7yTNCYlekhVsBThUcfb2kb1Lf2Ow3cjwL7ss66bvUc9+bwDGHtp3uJ9/GbJlZdphE=
谁能帮我 ?为什么我在红宝石部分做错了?我想复制linux命令行命令!