Note that there are some explanatory texts on larger screens.

plurals
  1. POReproducing Ruby OpenSSL private_encrypt output in C#
    text
    copied!<p>I have a simple Ruby script that I am using to do a private_encrypt on some HTTP headers to sign a web request that is to be sent to a ruby REST API, the API tests the Base64 encoded string against a Base64 encoded string it generates rather than decoding the Base64 and decrypting the data then testing the original string. </p> <p>The script I am using is </p> <pre><code>require "openssl" require "base64" path_to_cert = ARGV[0].dup plain_text = Base64.decode64(ARGV[1].dup) private_key = OpenSSL::PKey::RSA.new(File.read(path_to_cert)) puts Base64.encode64(private_key.private_encrypt(plain_text)) </code></pre> <p>The fact that the input is Base64 encoded is purely due to linebreaks and spaces in the input argument.</p> <p>To use this I am having to shell out to ruby using System.Diagnostics.Process and capture the StdOut, while this isn't a major problem and works I'd like to remove the dependency on ruby but I am unable to reproduce the output using the C# RsaCryptoServiceProvider.</p> <p>If I Base64 Encode the private_encrypt result of "SimpleString" using ruby i consistently get </p> <blockquote> <p>auReJzoPSW3AhzsfT3EH4rD7lc4y2CJ026xIOiV6kjl2OKIj8GnzrPosoJDg\nSHrvLVKrSxYlegYgJRMx+vaAHSAm7RXrZh5An2SnVuO3qITa2TJ78hTc3bAw\nCDm4i9/4qictjxEFfnPRe6 EYCa4b3dnM5moa1eo9zbQPBa1eS6ItRCX4C0G0\n1tJpQsEvuums363eAhTUAYa6yEWuINLPmE0USW6jfFNnsxw8Nv9SnC+ziomb\n/mwlt9dS5/mzKM8yFMH6hdQYLoqc0QpjT+xaZ1ZyJ6dG5MVG h3JtjIVRTOSd\n+pUU/bo+obEHbrftG8u2uJImLSA+/1e8aapHaa3WNg==</p> </blockquote> <p>When using the .Net</p> <pre><code>RsaCryptoServiceProvider.Encrypt("SimpleString", false) </code></pre> <p>The result is always a different output due to the fact it is encrypting with the public key.</p> <p>I have also tried </p> <pre><code>RsaCryptoServiceProvider.SignData </code></pre> <p>and while this always yields the same result, it is different to the result from ruby.</p> <p>Can I use some CryptoAPI directly from .Net that will allow me to achieve the same result as Ruby?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload