// test default key size
Assert.AreEqual (1024, rsa.KeySize, "ConstructorEmpty");
Assert.IsFalse (rsa.PersistKeyInCsp, "PersistKeyInCsp");
-#if NET_2_0
Assert.IsFalse (rsa.PublicOnly, "PublicOnly");
-#endif
}
[Test]
// test default key size
Assert.AreEqual (minKeySize, rsa.KeySize, "ConstructorKeySize");
Assert.IsFalse (rsa.PersistKeyInCsp, "PersistKeyInCsp");
-#if NET_2_0
Assert.IsFalse (rsa.PublicOnly, "PublicOnly");
-#endif
}
[Test]
- [Category ("TargetJvmNotSupported")]
public void ConstructorCspParameters ()
{
CspParameters csp = new CspParameters (1, null, "Mono1024");
// test default key size
Assert.AreEqual (1024, rsa.KeySize, "ConstructorCspParameters");
Assert.IsTrue (rsa.PersistKeyInCsp, "PersistKeyInCsp");
-#if NET_2_0
Assert.IsFalse (rsa.PublicOnly, "PublicOnly");
-#endif
}
[Test]
- [Category ("TargetJvmNotSupported")]
public void ConstructorKeySizeCspParameters ()
{
int keySize = 512;
rsa = new RSACryptoServiceProvider (keySize, csp);
Assert.AreEqual (keySize, rsa.KeySize, "ConstructorCspParameters");
Assert.IsTrue (rsa.PersistKeyInCsp, "PersistKeyInCsp");
-#if NET_2_0
Assert.IsFalse (rsa.PublicOnly, "PublicOnly");
-#endif
}
[Test]
public void TooSmallKeyPair ()
{
rsa = new RSACryptoServiceProvider (256);
-#if NET_2_0
// in 2.0 MS delay the creation of the key pair until it is required
// (same trick that Mono almost always used ;-) but they also delay
// the parameter validation (what Mono didn't). So here we must "get"
// the key (export) to trigger the exception
rsa.ToXmlString (true);
-#endif
}
[Test]
public void TooBigKeyPair ()
{
rsa = new RSACryptoServiceProvider (32768);
-#if NET_2_0
// in 2.0 MS delay the creation of the key pair until it is required
// (same trick that Mono almost always used ;-) but they also delay
// the parameter validation (what Mono didn't). So here we must "get"
// the key (export) to trigger the exception
rsa.ToXmlString (true);
-#endif
}
[Test]
rsa.VerifyHash (hash, "1.3.14.3.2.26", null);
}
-#if NET_2_0 && !NET_2_1
+#if !MOBILE
[Test]
[Category ("NotWorking")]
public void ImportDisposed ()
rsa.ToXmlString (true);
}
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void ExportWithoutCRT_2 ()
+ {
+ try {
+ rsa = new RSACryptoServiceProvider ();
+ rsa.FromXmlString (MonoXml384woCRT);
+ }
+ catch {
+ }
+ // exception is HERE!
+ rsa.ExportParameters (true);
+ }
+
// Validate that we can sign with every keypair and verify the signature
// With Windows this means that we can use Mono keypairs to sign and verify.
// For Mono this doesn't mean much.
// http://msdn.microsoft.com/library/en-us/cpguide/html/cpcongeneratingkeysforencryptiondecryption.asp
[Test]
- [Category ("TargetJvmNotSupported")]
public void Persistence_PersistKeyInCsp_False ()
{
CspParameters csp = new CspParameters (1, null, "Persistence_PersistKeyInCsp_False");
}
[Test]
- [Category ("TargetJvmNotSupported")]
public void Persistence_PersistKeyInCsp_True ()
{
CspParameters csp = new CspParameters (1, null, "Persistence_PersistKeyInCsp_True");
}
[Test]
- [Category ("TargetJvmNotSupported")]
public void Persistence_Delete ()
{
CspParameters csp = new CspParameters (1, null, "Persistence_Delete");
}
[Test]
- [Category ("TargetJvmNotSupported")]
public void UseMachineKeyStore ()
{
// note only applicable when CspParameters isn't used - which don't
{
rsa = new RSACryptoServiceProvider ();
rsa.FromXmlString ("<RSAKeyValue><Modulus>iSObDmmhDgrl4NiLaviFcpv4NdysBWJcqiVz3AQbPdajtXaQQ8VJdfRkixah132yKOFGCWZhHS3EuPMh8dcNwGwta2nh+m2IV6ktzI4+mZ7CSNAsmlDY0JI+H8At1vKvNArlC5jkVGuliYroJeSU/NLPLNYgspi7TtXGy9Rfug8=</Modulus><Exponent>EQ==</Exponent></RSAKeyValue>");
-#if NET_2_0
Assert.IsTrue (rsa.PublicOnly, "PublicOnly");
-#endif
string b64 = @"YgyAhscnTTIcDeLJTZcOYYyHVxNhV6d03jeZYjq0sPMEsfCCbE/NcFyYHD9BTuiduqPplCLbGpfZIZYJ6vAP9m5z4Q9eEw79kmEFCsm8wSKEo/gKiptVpwQ78VOPrWd/wEkTTeeg2nVim3JIsTKGFlV7rKxIWQhGN9aAqgP8nZI=";
byte [] bytes = Convert.FromBase64String (b64);
rsa.Decrypt (bytes, true);
Assert.IsNotNull (r.Decrypt (bytes, true));
}
-#if NET_2_0
-#if !NET_2_1
+#if !MOBILE
[Test]
[Category ("NotWorking")]
public void CspKeyContainerInfo_NewKeypair ()
rsa = new RSACryptoServiceProvider (minKeySize);
rsa.ImportCspBlob (blob);
}
-#endif
+
+ [Test] //bug 38054
+ public void NonExportableKeysAreNonExportable ()
+ {
+ var cspParams = new CspParameters();
+ cspParams.KeyContainerName = "TestRSAKey";
+ cspParams.Flags = CspProviderFlags.UseNonExportableKey;
+ var rsa = new RSACryptoServiceProvider(cspParams);
+ Assert.Throws<CryptographicException>(() => rsa.ExportParameters(true));
+ }
}
}