0

I am working with EDI - AS2. So I have to create a PrivateKey certificate (.pfx) and a PublicKey certificate (.cer). Here I sign my message with my PrivateKey certificate (.pfx) and share the PublicKey certificate (.cer) with my trading partner, so that they can verify the signature.

I have written the code to generate test PublicKey certificate (*.pfx). Following is the part of the code where I set properties of private key:

// create a new private key for the certificate
CX509PrivateKey privateKey = new CX509PrivateKey();
privateKey.ProviderName = "Microsoft Enhanced RSA and AES Cryptographic Provider";
privateKey.MachineContext = true;
privateKey.Length = 1024;
privateKey.KeySpec = X509KeySpec.XCN_AT_KEYEXCHANGE;
privateKey.ExportPolicy = X509PrivateKeyExportFlags.XCN_NCRYPT_ALLOW_PLAINTEXT_EXPORT_FLAG;
privateKey.Create();

above code is working fine when I use privateKey.Length = 1024 or 512. but out trading partner want us to create certificate with key size of 168 with 3DES and SHA1

Whenever I give privateKey.Length = 168 I get following error:

CertEnroll::CX509PrivateKey::Create: Invalid flags specified. 0x80090009 (-2146893815)

I am not able to figure out what change I need to do here to make it work.

Please help,

Thanks

Yash
  • 356
  • 1
  • 5
  • 22
  • 2
    Your partner is nuts. 168 is the keysize for 3DES, but the symmetric (3DES) key is not in and does not affect in any way the cert. The cert is only for RSA, and the smallest RSA size ever permitted was 512 for 'export' in the 1990s because it could be broken. 768 or 1024 was considered acceptable in the Clinton and Bush-Jr administrations, but no longer provides an adequate margin; nowadays most applications require 2048 and a few (like NSA's CNSAS) even more. – dave_thompson_085 Nov 16 '18 at 10:27
  • Thanks @dave_thompson_085, for the response. So you mean now we can not create a certificate with key length of 168? Is there any workaround for it? – Yash Nov 16 '18 at 12:03
  • What kind of workaround you are looking for? You need to clarify the requirements with your partner. As it was said, 3DES is symmetric algorithm and has nothing to do with public certificates. – Crypt32 Nov 16 '18 at 14:00
  • @Crypt32, Thanks for showing interest in solving my problem. My simple requirement is that I want to create a certificate which supports "3DES", "SHA1" and key length of 168 bit. How is it possible in c#? – Yash Nov 16 '18 at 14:16
  • We are sharing EDI files over AS2 protocol with our trading partner. So we have shared out public key certificate with each other. For sending the file we are signing the file with our certificate (private key) and encrypting with their certificate (public key). our certificate has 1024 key length and their certificate has 2048 key length. after sending a test file we received following response from them : "Our system will not support 1024 length. So, please send us the file with Encryption key length – 168." – Yash Nov 16 '18 at 14:18
  • 1
    It is not possible, because the requirement is not correctly defined. Again, when building X.509 certificates you can specify only *asymmetric* key algorithm and *asymmetric* key length. Common asymmetric algorithms include RSA and ECDSA (custom algorithms , such as GOST) may exist. DES/3DES is *symmetric* key and has no meaning in asymmetric context. SHA1 is valid term here, but 3DES is not. – Crypt32 Nov 16 '18 at 14:24
  • You are correct. Our certificate is RSA (1024 bit) and the certificate they have shared is RSA(2048 bit). We have to encrypt the file with 3DES before sending. But they want key length to be 168 bit – Yash Nov 16 '18 at 14:38
  • 1
    (@Crypt32) if you encrypt(ed) with 3DES then the symmetric encryption key length already is 168 and their response makes no sense. If you didn't encrypt with 3DES that maye be a mistake but it has nothing to do with any certificate. It's possible the actual problem is their system doesn't accept _signature_ with RSA-1024 -- that would be good practice -- but if so they have totally messed up their expression of this problem. If they actually want you to sign with RSA-2048 _then_ you do need a RSA-2048 cert&key. – dave_thompson_085 Nov 18 '18 at 15:52
  • Thank you so much for the support both of you dave_thompson_085 and Crypt32. There was mistake of our trading partner. Everything was correct from our end. So, there was nothing wrong in our certificate. If I encrypt with 3DES it is by default 168 bit key length. – Yash Nov 22 '18 at 15:03

0 Answers0