Note that there are some explanatory texts on larger screens.

plurals
  1. POPython and C# Cryptography: What i'm doing wrong?
    primarykey
    data
    text
    <p><strong>I need to encrypt text in python and decrypt in C #. In python, I have this code:</strong></p> <p>I have this code in Python:</p> <pre><code>def genKey(): rsa = RSA.gen_key(2048, 65537) rsa.save_key('c:/temp/priv-key.pem', callback=passwordCallback) rsa.save_pub_key('c:/temp/pub-key.pem') def encrypt(): varkey = readkey('c:/temp/pub-key.pem') bio = BIO.MemoryBuffer(varkey) rsa = RSA.load_pub_key_bio(bio) encrypted = rsa.public_encrypt('My Text Here.', RSA.pkcs1_oaep_padding) f = open("c:/temp/cript.txt", "w") f.write(encrypted) f.close() </code></pre> <p>This code uses M2Crypto.</p> <p><strong>Like I said, I want to decrypt the result generated up in C #. Below is my code:</strong></p> <pre><code>static void Main(string[] args) { string text = GetText(); System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding(); Byte[] payload = encoding.GetBytes(text); byte[] b = System.IO.File.ReadAllBytes(@"C:\temp\priv-key.pem"); System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); OpenSSL.Core.BIO bio = new OpenSSL.Core.BIO(b); OpenSSL.Crypto.CryptoKey key = OpenSSL.Crypto.CryptoKey.FromPrivateKey(bio, "mypassword"); RSA rsa = key.GetRSA(); byte[] result = rsa.PrivateDecrypt(payload, RSA.Padding.OAEP); } </code></pre> <p><strong>The problem is this line:</strong></p> <pre><code>byte[] result = rsa.PrivateDecrypt(payload, RSA.Padding.OAEP); </code></pre> <p>When it is executed, this error occurs:</p> <pre><code>error:0407A079:rsa routines:RSA_padding_check_PKCS1_OAEP:oaep decoding error error:04065072:rsa routines:RSA_EAY_PRIVATE_DECRYPT:padding check failed </code></pre> <p>The gurus of Cryptography and C# can help me?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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