RE: problem with System.Security.Cryptography
From: Christian France (France_at_discussions.microsoft.com)
Date: 12/07/04
- Next message: Peter Steele: "Creating SC Certificate Request with IEnroll2"
- Previous message: Peter Steele: "Re: CoCreateInstance Fails with "ClassFactory cannot supply...""
- In reply to: lelteto: "RE: problem with System.Security.Cryptography"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Tue, 7 Dec 2004 03:47:03 -0800
I am trying to decrypt correctly encrypted data
"lelteto" wrote:
> Are you trying to decrypt correctly encrypted data? Or just trying to decrypt
> some 'arbitrary' modulus-length data? In the latter case you may supply data
> that is (as an integer data) larger than the modulus value (although the same
> length in bytes) - in which case you should get the mentioned error.
>
> Laszlo Elteto
> SafeNet, Inc.
>
> "Christian from France" wrote:
>
> > The following code decrypt a string input :
> > ==================================================
> > string Key_Name="my.key.name";
> > System.Security.Cryptography.CspParameters cp = new
> > System.Security.Cryptography.CspParameters();
> > cp.KeyContainerName = Key_Name;
> >
> > System.Security.Cryptography.RSACryptoServiceProvider v_coder = new
> > System.Security.Cryptography.RSACryptoServiceProvider(cp);
> > System.Security.Cryptography.RSAParameters v_key=new
> > System.Security.Cryptography.RSAParameters();
> >
> > byte[] dataToDecrypt = Convert.FromBase64String(input);
> > v_coder.ImportParameters(v_coder.ExportParameters(true));
> > byte[] decryptedData=v_coder.Decrypt(dataToDecrypt,false);
> > output= new System.Text.UTF8Encoding().GetString(decryptedData);
> > ==================================================
> >
> > Sometimes this code do not work.
> > I obtain the following error :
> > "Données incorrectes." (in french) "Incorrect data" (in english)
> > Exception.StackTrace : -> at
> > System.Security.Cryptography.RSACryptoServiceProvider._DecryptPKWin2KEnh(IntPtr hPubKey, Byte[] rgbKey, Boolean fOAEP)
> > at System.Security.Cryptography.RSACryptoServiceProvider.Decrypt(Byte[]
> > rgb, Boolean fOAEP)
> >
> > The only solution i have found is to compile a new version of my crypt and
> > decrypt code with another value for the string "Key_Name".
> >
> > My code run every day and this problem appears 3 times in two months.
> >
> > Is anybody has an explanation ?
> >
> > Thanks,
> >
> > Christian
> >
- Next message: Peter Steele: "Creating SC Certificate Request with IEnroll2"
- Previous message: Peter Steele: "Re: CoCreateInstance Fails with "ClassFactory cannot supply...""
- In reply to: lelteto: "RE: problem with System.Security.Cryptography"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]