From d0cf2c890aa17bbfc7ceab9167de5cd86f68276a Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Thu, 14 Sep 2017 19:36:59 +0200 Subject: [PATCH] fix-38054 --- .../RSACryptoServiceProvider.cs | 1 + .../RSACryptoServiceProviderTest.cs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/mcs/class/corlib/System.Security.Cryptography/RSACryptoServiceProvider.cs b/mcs/class/corlib/System.Security.Cryptography/RSACryptoServiceProvider.cs index a8ebc812da3..16fdfa15e5e 100644 --- a/mcs/class/corlib/System.Security.Cryptography/RSACryptoServiceProvider.cs +++ b/mcs/class/corlib/System.Security.Cryptography/RSACryptoServiceProvider.cs @@ -111,6 +111,7 @@ namespace System.Security.Cryptography { store = new KeyPairPersistence (p); bool exists = store.Load (); bool required = (p.Flags & CspProviderFlags.UseExistingKey) != 0; + privateKeyExportable = (p.Flags & CspProviderFlags.UseNonExportableKey) == 0; if (required && !exists) throw new CryptographicException ("Keyset does not exist"); diff --git a/mcs/class/corlib/Test/System.Security.Cryptography/RSACryptoServiceProviderTest.cs b/mcs/class/corlib/Test/System.Security.Cryptography/RSACryptoServiceProviderTest.cs index 6e44e3235b2..c9011cb41f6 100644 --- a/mcs/class/corlib/Test/System.Security.Cryptography/RSACryptoServiceProviderTest.cs +++ b/mcs/class/corlib/Test/System.Security.Cryptography/RSACryptoServiceProviderTest.cs @@ -1403,6 +1403,16 @@ public class RSACryptoServiceProviderTest { rsa = new RSACryptoServiceProvider (minKeySize); rsa.ImportCspBlob (blob); } + + [Test] //bug 38054 + public void NonExportableKeysAreNonExportable () + { + var cspParams = new CspParameters(); + cspParams.KeyContainerName = "TestRSAKey"; + cspParams.Flags = CspProviderFlags.UseNonExportableKey; + var rsa = new RSACryptoServiceProvider(cspParams); + Assert.Throws(() => rsa.ExportParameters(true)); + } } } -- 2.25.1