How to Wrap Symmetric Key and IV in C#

1.5k Views Asked by At

Is there an existing .NET API for performing a Triple DES Key Wrap ?
Documentation here.

I have generated 192 bit symmetric key + 64 bit initialization vector (IV) for 256 bit total.

Currently, my code only encrypts the symmetric key as follows:

        byte[] rawData = ReadFile("C:\\ReceiverTest.crt");
        X509Certificate2 x509 = new X509Certificate2();
        x509.Import(rawData);
        var receiverPublicKey = x509.PublicKey.Key.ToXmlString(false);

        RSACryptoServiceProvider receiverCipher = new RSACryptoServiceProvider();
        receiverCipher.FromXmlString(receiverPublicKey);

        // Encrypt the secret with the receiver's public key (so only they can decrypt)
        byte[] keyEncryptedBytes = receiverCipher.Encrypt(_cryptoHelper.SymmetricKey, false);             
        // Releases all resources
        receiverCipher.Clear();

        return keyEncryptedBytes;

I am using http://www.w3.org/2001/04/xmlenc#tripledes-cbc as the encryption algorithm.
Algorithm for signing the SAML Response - http://www.w3.org/2000/09/xmldsig#rsa-sha1
Encryption key transportation - http://www.w3.org/2001/04/xmlenc#rsa-1_5

The Service Provider is unable to decrypt my digest value until they get the IV wrapped with the symmetric key.

Thank you in advance for any help!
-Carrie

0

There are 0 best solutions below