我有一个系统应该给我的伴侣一个公钥来解密文本。我想要的是如何使用我的私钥签署该文本。这就是我这样做的方法,但它失败了。
require 'openssl'
require 'base64'
require 'digest/sha1'
@date = Date.today.strftime("%m/%d/%Y")
text_to_sign = "#{@order.phone_no}" + "#{@order.name}" + "#{@order.pay_type}" + "#{@order.pay_type}" + "1" + "MABIRA" + "81W30DI846" + "#{@date}" + "PULL" + "1" + "#{@cart.total_price}" + "#{@order.phone_no}" + ""
cipher = OpenSSL::Cipher.new 'aes-256-cbc'
cipher.encrypt
cipher.key = cipher.random_key
cipher.iv = cipher.random_iv
encrypted = cipher.update(text_to_sign) + cipher.final
private_key = OpenSSL::PKey::RSA.new(File.read('Private.key'), password)
ciphertext = private_key.private_encrypt(encrypted)
ciphertext.encoding
signed_text = Base64.encode64(ciphertext).gsub("\n", '')
puts signed_text
signed_text