OpenSSL.NET 将 Ruby 示例移植到 C#(来自 RailsCasts 143 paypal-security)
我正在关注有关 PayPal 安全性的 RailsCasts 剧集。我尝试将此代码移植到 C# 并使用 OpenSSL.NET
也可以这样做不使用 OpenSSL 包装器库,因为它使用一些非托管代码?
我尝试移植的 ruby 代码是这样的:
def encrypt_for_paypal(values)
signed = OpenSSL::PKCS7::sign(OpenSSL::X509::Certificate.new(APP_CERT_PEM), OpenSSL::PKey::RSA.new(APP_KEY_PEM, ''), values.map { |k, v| "#{k}=#{v}" }.join("\n"), [], OpenSSL::PKCS7::BINARY)
OpenSSL::PKCS7::encrypt([OpenSSL::X509::Certificate.new(PAYPAL_CERT_PEM)], signed.to_der, OpenSSL::Cipher::Cipher::new("DES3"), OpenSSL::PKCS7::BINARY).to_s.gsub("\n", "")
end
有谁知道如何使用 C# OpenSSL 包装器执行此操作?
I am following through the RailsCasts episode on PayPal security. I am try to port this code to C# and am using OpenSSL.NET
Also is it possible to do this without using the OpenSSL wrapper library as that uses some unmanaged code?
The ruby code that I am trying to port is this:
def encrypt_for_paypal(values)
signed = OpenSSL::PKCS7::sign(OpenSSL::X509::Certificate.new(APP_CERT_PEM), OpenSSL::PKey::RSA.new(APP_KEY_PEM, ''), values.map { |k, v| "#{k}=#{v}" }.join("\n"), [], OpenSSL::PKCS7::BINARY)
OpenSSL::PKCS7::encrypt([OpenSSL::X509::Certificate.new(PAYPAL_CERT_PEM)], signed.to_der, OpenSSL::Cipher::Cipher::new("DES3"), OpenSSL::PKCS7::BINARY).to_s.gsub("\n", "")
end
Does anyone know how to do this with C# OpenSSL wrapper?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果我发现了一篇文章解释了如何在 C# 中执行此操作。因此,请阅读并遵循该教程。我使用 Cygwin Bash Shell 来创建密钥。我已经包含了我使用的代码,因为它可能会有所帮助:)
这是书中发布的所有代码 专业 PayPal 电子商务 作者:Damon Williams
FormEncryption 类
然后是 html 表单
Turns out I found an article that explains how to do this for C#. So read an follow that tutorial. I used Cygwin Bash Shell to create the keys. I've included the code that I used as it may be helpful :)
This is all code that was published in the book Pro PayPal E-Commerce by Damon Williams
The FormEncryption class
Then the html form