Skip to content
Advertisement

How to correctly decrypt data in python using RSA Private Key BLOB from windows

I have successfully constructed RSA2 key by splitting private key blob into n, e, d, p, q values with the following code:

JavaScript

I did not get any error. However, when I’m trying to decrypt data with this key I get an error: incorrect decryption. I use this piece of code:

JavaScript

At the same time I see that standart windows functions do it well on the same blob:

JavaScript

Why do I faced “incorrect decryption” error? I think I might use a wrong padding in python..

Also this is my keyblob:

JavaScript

This is an encrypted code:

JavaScript

Advertisement

Answer

Decryption does not work for two reasons:

  • CryptDecrypt(), (s. Remarks) uses the little endian format, i.e. the ciphertext must be reversed.
  • The required padding is not OAEP, but PKCS#1 v1.5 padding.

If this is fixed, e.g. with

JavaScript

decryption works:

JavaScript

The plaintext is a 12 bytes BLOBHEADER structure followed by the 32 bytes AES key defined by it.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement