Home All Groups Group Topic Archive Search About

error when I use AES with CAPICOM

Author
7 Mar 2005 7:30 PM
dibakar ray via .NET 247
Hi all,
I am trying to write a small utility using CAPICOM. What I am trying to do is use a smart card and create enveloped data.
As long as I use alogorithm like rs2,rs4 or triple des the code works fine.
The moment i change the algorithm.name to CAPICOM_ENCRYPTION_ALGORITHM_AES
I get an error
System.Runtime.InteropServices.COMException' occurred in WindowsApplication1.exe
Additional information: The requested operation is not allowed in this process.

The code I am trying is given below -
EnvelopedData oEnvelop = new CAPICOM.EnvelopedData();
            Certificates oCerts;

            String sr = "ppwrd.txt";
            String ofile = "test.txt";
                            // add receipients here  oEnvelop.Recipients.Add(ocert);

            oEnvelop.Algorithm.KeyLength=CAPICOM.CAPICOM_ENCRYPTION_KEY_LENGTH.CAPICOM_ENCRYPTION_KEY_LENGTH_MAXIMUM;

oEnvelop.Algorithm.Name =CAPICOM.CAPICOM_ENCRYPTION_ALGORITHM.CAPICOM_ENCRYPTION_ALGORITHM_AES;
                //CAPICOM_ENCRYPTION_ALGORITHM_RC4;
                //CAPICOM_ENCRYPTION_ALGORITHM_AES;
                //CAPICOM_ENCRYPTION_ALGORITHM_RC2;

            try
            {
//ERROR HERE
                oEnvelop.Content = ReadInputFile( sr );
            }
            catch ( IOException exc )
            {
                Console.WriteLine( "### ERROR ### Unable to open or read {0}.  Details:  {1}", sr, exc.Message );
                ok=false;                     
            }
            if ( ok )
            {
                try
                {
                    string envelopedMsg;
                    envelopedMsg=oEnvelop.Encrypt(CAPICOM_ENCODING_TYPE.CAPICOM_ENCODE_BASE64);

                    WriteOutputFile( ofile, envelopedMsg );
                    Console.WriteLine( "{0} successfully encrypted into {1} ",  sr, ofile);
                }
                catch ( COMException exc )
                {
                    Console.WriteLine( "### ERROR ### CAPICOM error during encryption.  Details:  {0}", exc.Message );
                }
                catch ( IOException exc )
                {
                    Console.WriteLine( "### ERROR ### Unable to write encrypted data to {0}", ofile );
                    Console.WriteLine( "Details:  " + exc.Message );
                }

When I check my locals under the CAPICOM.AlgorithmClass value of Name is still     CAPICOM_ENCRYPTION_ALGORITHM_RC2
Any help will be appricated.
Thanks in advance   


--------------------------------
From: dibakar ray

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>0sBOkPRl9UGVanfe+xUjGg==</Id>