开发者

DSACryptoServiceProvider.EncriptionPrivateKey under VS2010 stopped to work

When I convert my VS2008 project to VS2010 the following code:

        private static readonly byte[] EncriptionPrivateKey = {
            0x07, 0x02, 0x00, 0x00,
            0x00, 0x22, 0x00, 0x00,
            0x44, 0x53, 0x53, 0x32,
            0x00, 0x04, 0x00, 0x00,
            ....

        CspParameters csp = new CspParameters(13, null, null)
            { Flags = CspProviderFlags.UseMachineKey}; 

        using (DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(csp))
        {
            dsa.ImportCspBlob(EncriptionPrivateKey);

Stopped to work. execution of 'ImportCspBlob' method throws CryptographicException:

The parameter is incorrect.

And MSDN has nothing about exception in this method: http://msdn.microsoft.com/en-us/library/system.security.cryptography.dsacryptoserviceprovider.importcspblob.aspx

Any i开发者_JS百科deas why and how to resolve?

Thanks a lot!

P.S. I still using .NET 3.5 framework


The trick was that I launched those code from MSTest that was automatically converted into .NET 4.0 and as a result application (and listed source code) were launched under .NET 4.0 with settings specific for .NET 4.0...

Knowing that allowed me to find a workaround for problem:

In original source code:

CspParameters csp = new CspParameters(13, null, null)
   { Flags = CspProviderFlags.UseMachineKey};

It is necessary to remove those Flag assignment... I've found those keys description: http://msdn.microsoft.com/en-us/library/system.security.cryptography.cspproviderflags.aspx but it is unclear how they work and what they actually do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜