1

Our goal is to send SOAP messages to a web service, signing these messages using TripleDesRSA15 algorithm.

Web service staff sent us a .pfx file, where certificate for encryption is stored. I'm able to extract private key from this certificate and its first line is BEGIN RSA PRIVATE KEY.

Then I store this private key in a server and use it for encryption using python:

pkey=open("pkey.key", "rb").read()

from pyDes import *
pyDes=triple_des(pkey)

But python module pyDes complaints: *** ValueError: Invalid triple DES key size. Key must be either 16 or 24 bytes long

Did I use wrong key or use it in a wrong way?

2
  • I'm confused why you used pyDes.triple_des() on a RSA private key.
    – schroeder
    Dec 9, 2015 at 15:54
  • I am not convinced you have the wrong key. See MS reference Dec 9, 2015 at 21:05

1 Answer 1

4

How to use RSA private key for TripleDES encryption?

You don't!

RSA and 3DES are two completely different encryption algorithms with completely different properties. For a start, RSA uses a key pair (encryption and decryption key, respectively; this is known as asymmetric or public-key cryptography) while 3DES (because DES) uses only a single key for both encryption and decryption (called symmetric cryptography).

If you don't know exactly what you are doing (and not to be disparaging, but based on your question, I get the distinct feeling that you don't), you really shouldn't be doing encryption on your own. There are just far too many ways to mess up, in ways that puts data at risk, even when using well-known and time-proven algorithms like these (let alone if you are designing something entirely of your own).

Instead, you should delegate the task of data secrecy and authenticity to appropriate libraries, perhaps through Python's TLS support (same as your web browser uses when connecting to a HTTPS server), and just ask for a secure pipe to the remote system. The odds of getting that wrong are vastly smaller.

2
  • 1
    I think the RSA15 refers to using the PKCS 1.5 key padding algorithm. Dec 9, 2015 at 14:25
  • Thanks! I'll contact web service stuff and ask to send me correct keys... Dec 9, 2015 at 16:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .