* AllTests2.cs: Updated to NUnit 2.2 Assert.
* CipherModeTest.cs: New. Tests supported CipherMode for all
SymmetricAlgorithm included in the framework (enum contains two more
modes that aren't implemented in any Fx version).
* CryptoConfigTest.cs: Ajusted new OID (for old names) in Fx 2.0.
* CryptoStreamTest.cs: Fixed different reported exception in Fx 2.0.
Fixed a bad test.
* CspProviderFlagsTest.cs: New. Test the values of the enum.
* DSACryptoServiceProviderTest.cs: Added new tests for new public
properties and methods added in Fx 2.0. Duplicated test to import a
key pair into a disposed instance (works in Fx 2.0). Removed all
[Ignore]s in NET_2_0 as the MS class/runtime has been fixed.
* DSASignatureDeformatterTest.cs: Converted from NUnit 1 to 2.2. Fixed
different reported exception in Fx 2.0.
* DSASignatureFormatterTest.cs: Converted from NUnit 1 to 2.2. Fixed
different reported exception in Fx 2.0.
* HMACRIPEMD160Test.cs: Fixed tests using TransformFinalBlock.
* HMACSHA1Test.cs: Fixed tests so they work on both NET_1_1 and
NET_2_0 profiles (as HMACSHA1 changed it's base class).
* HashAlgorithmTest.cs: Fixed different reported exception in Fx 2.0.
Removed [Ignore] in NET_2_0 as the MS class/runtime has been fixed.
* MACTripleDESTest.cs: Fixed tests so they work on both NET_1_1 and
NET_2_0 profiles.
* PKCS1MaskGenerationMethodTest.cs: Removed [Ignore] in NET_2_0 as the
MS class has been fixed.
* PaddingModeTest.cs: Added new tests for the two new padding mode
introduced in Fx 2.0. Converted to NUnit 2.2.
* PasswordDeriveBytesTest.cs: Removed [ExpectedException] for
StrangeBehaviour test as it is fixed in Fx 2.0.
* RC2Test.cs: Changed exception from CryptographicException to
CryptographicUnexpectedOperationException for Fx 1.1/2.0.
* RIPEMD160Test.cs: Fixed tests using TransformFinalBlock.
* RSACryptoServiceProviderTest.cs: Added new tests for new public
properties and methods added in Fx 2.0. Duplicated test to import a
key pair into a disposed instance (works in Fx 2.0). Duplicated test
to sign with a null OID (Fx 2.0 use SHA1 oid in this case).
* RSAOAEPKeyExchangeDeformatterTest.cs: Changed exception for a key
exchange with no key (to match Fx 2.0).
* RSAOAEPKeyExchangeFormatterTest.cs: Changed exception for a key
exchange with no key (to match Fx 2.0).
* RSAPKCS1KeyExchangeFormatterTest.cs: Changed exception for a key
exchange with no key (to match Fx 2.0). Removed [Ignore] in NET_2_0 as
the MS class/runtime has been fixed.
* RSAPKCS1SignatureDeformatterTest.cs: Null keys, in constructor or in
SetKey method, now throw an ArgumentNullException in Fx 2.0.
* RSAPKCS1SignatureFormatterTest.cs: Null keys, in constructor or in
SetKey method, now throw an ArgumentNullException in Fx 2.0.
* Rfc2898DeriveBytesTest.cs: Typecasted a null as a string.
* SymmetricAlgorithm2Test.cs: In Fx 2.0 an empty IV now throws a
CryptographicException.
* ToBase64TransformTest.cs: Fixed different reported exception in Fx 2.0.
Removed [Ignore] in NET_2_0 as the MS class/runtime has been fixed.
svn path=/trunk/mcs/; revision=30836
//
// Authors:
// Thomas Neidhart (tome@sbox.tugraz.at)
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot (sebastien@ximian.com)
//
// Portions (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using NUnit.Framework;
namespace MonoTests.System.Security.Cryptography {
- /// <summary>
- /// Combines all available crypto unit tests into one test suite.
- /// </summary>
- public class AllTests {
+
+ public class AllTests {
// because most crypto stuff works with byte[] buffers
static public void AssertEquals (string msg, byte[] array1, byte[] array2)
{
if ((array1 == null) && (array2 == null))
return;
if (array1 == null)
- Assertion.Fail (msg + " -> First array is NULL");
+ Assert.Fail (msg + " -> First array is NULL");
if (array2 == null)
- Assertion.Fail (msg + " -> Second array is NULL");
+ Assert.Fail (msg + " -> Second array is NULL");
bool a = (array1.Length == array2.Length);
if (a) {
}
msg += " -> Expected " + BitConverter.ToString (array1, 0);
msg += " is different than " + BitConverter.ToString (array2, 0);
- Assertion.Assert (msg, a);
+ Assert.IsTrue (a, msg);
}
public static byte[] dsaG = { 0x3D, 0x4F, 0xCC, 0x78, 0x6A, 0x7A, 0x23, 0xF1, 0x41, 0x76, 0xEB, 0xB0, 0x0F, 0xD5, 0x0F, 0x78, 0x21, 0x73, 0x83, 0xC2, 0x1B, 0xF4, 0x7E, 0x68, 0xB2, 0x4B,
+2004-07-07 Sebastien Pouliot <sebastien@ximian.com>
+
+ * AllTests2.cs: Updated to NUnit 2.2 Assert.
+ * CipherModeTest.cs: New. Tests supported CipherMode for all
+ SymmetricAlgorithm included in the framework (enum contains two more
+ modes that aren't implemented in any Fx version).
+ * CryptoConfigTest.cs: Ajusted new OID (for old names) in Fx 2.0.
+ * CryptoStreamTest.cs: Fixed different reported exception in Fx 2.0.
+ Fixed a bad test.
+ * CspProviderFlagsTest.cs: New. Test the values of the enum.
+ * DSACryptoServiceProviderTest.cs: Added new tests for new public
+ properties and methods added in Fx 2.0. Duplicated test to import a
+ key pair into a disposed instance (works in Fx 2.0). Removed all
+ [Ignore]s in NET_2_0 as the MS class/runtime has been fixed.
+ * DSASignatureDeformatterTest.cs: Converted from NUnit 1 to 2.2. Fixed
+ different reported exception in Fx 2.0.
+ * DSASignatureFormatterTest.cs: Converted from NUnit 1 to 2.2. Fixed
+ different reported exception in Fx 2.0.
+ * HMACRIPEMD160Test.cs: Fixed tests using TransformFinalBlock.
+ * HMACSHA1Test.cs: Fixed tests so they work on both NET_1_1 and
+ NET_2_0 profiles (as HMACSHA1 changed it's base class).
+ * HashAlgorithmTest.cs: Fixed different reported exception in Fx 2.0.
+ Removed [Ignore] in NET_2_0 as the MS class/runtime has been fixed.
+ * MACTripleDESTest.cs: Fixed tests so they work on both NET_1_1 and
+ NET_2_0 profiles.
+ * PKCS1MaskGenerationMethodTest.cs: Removed [Ignore] in NET_2_0 as the
+ MS class has been fixed.
+ * PaddingModeTest.cs: Added new tests for the two new padding mode
+ introduced in Fx 2.0. Converted to NUnit 2.2.
+ * PasswordDeriveBytesTest.cs: Removed [ExpectedException] for
+ StrangeBehaviour test as it is fixed in Fx 2.0.
+ * RC2Test.cs: Changed exception from CryptographicException to
+ CryptographicUnexpectedOperationException for Fx 1.1/2.0.
+ * RIPEMD160Test.cs: Fixed tests using TransformFinalBlock.
+ * RSACryptoServiceProviderTest.cs: Added new tests for new public
+ properties and methods added in Fx 2.0. Duplicated test to import a
+ key pair into a disposed instance (works in Fx 2.0). Duplicated test
+ to sign with a null OID (Fx 2.0 use SHA1 oid in this case).
+ * RSAOAEPKeyExchangeDeformatterTest.cs: Changed exception for a key
+ exchange with no key (to match Fx 2.0).
+ * RSAOAEPKeyExchangeFormatterTest.cs: Changed exception for a key
+ exchange with no key (to match Fx 2.0).
+ * RSAPKCS1KeyExchangeFormatterTest.cs: Changed exception for a key
+ exchange with no key (to match Fx 2.0). Removed [Ignore] in NET_2_0 as
+ the MS class/runtime has been fixed.
+ * RSAPKCS1SignatureDeformatterTest.cs: Null keys, in constructor or in
+ SetKey method, now throw an ArgumentNullException in Fx 2.0.
+ * RSAPKCS1SignatureFormatterTest.cs: Null keys, in constructor or in
+ SetKey method, now throw an ArgumentNullException in Fx 2.0.
+ * Rfc2898DeriveBytesTest.cs: Typecasted a null as a string.
+ * SymmetricAlgorithm2Test.cs: In Fx 2.0 an empty IV now throws a
+ CryptographicException.
+ * ToBase64TransformTest.cs: Fixed different reported exception in Fx 2.0.
+ Removed [Ignore] in NET_2_0 as the MS class/runtime has been fixed.
+
2004-06-23 Sebastien Pouliot <sebastien@ximian.com>
* CryptoStreamTest.cs: Added two tests for bug #60573. One shows that
--- /dev/null
+//
+// CipherModeTest.cs - NUnit Test Cases for CipherMode
+//
+// Author:
+// Sebastien Pouliot <sebastien@ximian.com>
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Security.Cryptography;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Security.Cryptography {
+
+ [TestFixture]
+ public class CipherModeTest {
+
+ // Enum tests
+
+ [Test]
+ public void CipherModeEnum ()
+ {
+ Assert.AreEqual (1, (int)CipherMode.CBC, "CBC");
+ Assert.AreEqual (4, (int)CipherMode.CFB, "CFB");
+ Assert.AreEqual (5, (int)CipherMode.CTS, "CTS");
+ Assert.AreEqual (2, (int)CipherMode.ECB, "ECB");
+ Assert.AreEqual (3, (int)CipherMode.OFB, "OFB");
+ }
+
+ // SymmetricAlgorithm tests
+
+ private byte[] GetKey (SymmetricAlgorithm sa)
+ {
+ byte[] key = new byte [sa.KeySize >> 3];
+ // no weak key this way (DES, TripleDES)
+ for (byte i = 0; i < key.Length; i++)
+ key [i] = i;
+ return key;
+ }
+
+ private byte[] GetIV (SymmetricAlgorithm sa)
+ {
+ return new byte [sa.BlockSize >> 3];
+ }
+
+ private string Roundtrip (SymmetricAlgorithm sa, CipherMode mode)
+ {
+ sa.Key = GetKey (sa);
+ sa.IV = GetIV (sa);
+ sa.Mode = mode;
+
+ // two full blocks
+ int bs = (sa.BlockSize >> 3) * 2;
+ byte[] data = new byte [bs]; // in bytes
+ ICryptoTransform enc = sa.CreateEncryptor ();
+ byte[] encdata = enc.TransformFinalBlock (data, 0, data.Length);
+ string result = BitConverter.ToString (encdata);
+
+ ICryptoTransform dec = sa.CreateDecryptor ();
+ byte[] decdata = dec.TransformFinalBlock (encdata, 0, encdata.Length);
+
+ for (int i = 0; i < bs; i++)
+ Assert.AreEqual (data [i], decdata [i], i.ToString ());
+
+ return result;
+ }
+
+ [Test]
+ public void DES_ECB ()
+ {
+ Assert.AreEqual ("A5-17-3A-D5-95-7B-43-70-A5-17-3A-D5-95-7B-43-70-E4-81-A8-D3-97-14-D0-DE",
+ Roundtrip (DES.Create (), CipherMode.ECB), "Encrypted data");
+ }
+
+ [Test]
+ public void DES_CBC ()
+ {
+ Assert.AreEqual ("A5-17-3A-D5-95-7B-43-70-79-6F-FD-B4-90-21-70-9D-FF-C8-76-01-24-7C-C3-82",
+ Roundtrip (DES.Create (), CipherMode.CBC), "Encrypted data");
+ }
+
+ [Test]
+ public void DES_CFB ()
+ {
+ Assert.AreEqual ("A5-AA-9B-16-02-77-16-A1-86-BC-38-B6-E5-BA-53-4C-A5-F9-49-21-A9-8E-84-A0",
+ Roundtrip (DES.Create (), CipherMode.CFB), "Encrypted data");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void DES_OFB ()
+ {
+ Assert.AreEqual ("not implemented in any released framework",
+ Roundtrip (DES.Create (), CipherMode.OFB), "Encrypted data");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void DES_CTS ()
+ {
+ Assert.AreEqual ("not implemented in any released framework",
+ Roundtrip (DES.Create (), CipherMode.CTS), "Encrypted data");
+ }
+
+ [Test]
+ public void RC2_ECB ()
+ {
+ Assert.AreEqual ("9C-4B-FE-6D-FE-73-9C-2B-9C-4B-FE-6D-FE-73-9C-2B-AB-C5-6E-FB-C4-0E-63-34",
+ Roundtrip (RC2.Create (), CipherMode.ECB), "Encrypted data");
+ }
+
+ [Test]
+ public void RC2_CBC ()
+ {
+ Assert.AreEqual ("9C-4B-FE-6D-FE-73-9C-2B-52-8F-C8-47-2B-66-F9-70-B2-67-CF-23-D7-D7-6D-A6",
+ Roundtrip (RC2.Create (), CipherMode.CBC), "Encrypted data");
+ }
+
+ [Test]
+ public void RC2_CFB ()
+ {
+ Assert.AreEqual ("9C-5A-41-95-9A-15-12-C2-54-1C-9C-6C-4B-65-A0-36-DD-7F-2B-0D-D5-D2-C0-CD",
+ Roundtrip (RC2.Create (), CipherMode.CFB), "Encrypted data");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void RC2_OFB ()
+ {
+ Assert.AreEqual ("not implemented in any released framework",
+ Roundtrip (RC2.Create (), CipherMode.OFB), "Encrypted data");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void RC2_CTS ()
+ {
+ Assert.AreEqual ("not implemented in any released framework",
+ Roundtrip (RC2.Create (), CipherMode.CTS), "Encrypted data");
+ }
+
+ [Test]
+ public void Rijndael_ECB ()
+ {
+ Assert.AreEqual ("F2-90-00-B6-2A-49-9F-D0-A9-F3-9A-6A-DD-2E-77-80-F2-90-00-B6-2A-49-9F-D0-A9-F3-9A-6A-DD-2E-77-80-9F-3B-75-04-92-6F-8B-D3-6E-31-18-E9-03-A4-CD-4A",
+ Roundtrip (Rijndael.Create (), CipherMode.ECB), "Encrypted data");
+ }
+
+ [Test]
+ public void Rijndael_CBC ()
+ {
+ Assert.AreEqual ("F2-90-00-B6-2A-49-9F-D0-A9-F3-9A-6A-DD-2E-77-80-D4-E9-69-25-C0-BF-CF-FB-52-F8-A1-87-EE-77-4A-AB-C3-28-91-ED-46-6E-6F-98-C1-4D-65-14-ED-9D-1E-5B",
+ Roundtrip (Rijndael.Create (), CipherMode.CBC), "Encrypted data");
+ }
+#if NET_2_0
+ [Test]
+ public void Rijndael_CFB ()
+ {
+ Assert.AreEqual ("F2-90-00-B6-2A-49-9F-D0-A9-F3-9A-6A-DD-2E-77-80-D4-E9-69-25-C0-BF-CF-FB-52-F8-A1-87-EE-77-4A-AB-26-03-7F-B7-B5-88-AE-0A-F8-AF-1E-CF-9C-F5-3A-8A",
+ Roundtrip (Rijndael.Create (), CipherMode.CFB), "Encrypted data");
+ }
+#else
+ // CFB was confused with OFB in Fx 1.0 and 1.1 (and wasn't supported because of that)
+ // However Mono does support it (because the same code is executed for all managed ciphers).
+ [Test]
+ public void Rijndael_CFB ()
+ {
+ try {
+ Assert.AreEqual ("F2-90-00-B6-2A-49-9F-D0-A9-F3-9A-6A-DD-2E-77-80-D4-E9-69-25-C0-BF-CF-FB-52-F8-A1-87-EE-77-4A-AB-26-03-7F-B7-B5-88-AE-0A-F8-AF-1E-CF-9C-F5-3A-8A",
+ Roundtrip (Rijndael.Create (), CipherMode.CFB), "Encrypted data");
+ }
+ catch (CryptographicException) {
+ // we assume this is the bugged MS implementation
+ }
+ }
+#endif
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Rijndael_OFB ()
+ {
+ Assert.AreEqual ("not implemented in any released framework",
+ Roundtrip (Rijndael.Create (), CipherMode.OFB), "Encrypted data");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Rijndael_CTS ()
+ {
+ Assert.AreEqual ("not implemented in any released framework",
+ Roundtrip (Rijndael.Create (), CipherMode.CTS), "Encrypted data");
+ }
+
+ [Test]
+ public void TripleDES_ECB ()
+ {
+ Assert.AreEqual ("89-4B-C3-08-54-26-A4-41-89-4B-C3-08-54-26-A4-41-A3-CF-6E-C8-8B-D9-7D-73",
+ Roundtrip (TripleDES.Create (), CipherMode.ECB), "Encrypted data");
+ }
+
+ [Test]
+ public void TripleDES_CBC ()
+ {
+ Assert.AreEqual ("89-4B-C3-08-54-26-A4-41-06-8E-DF-B5-F0-23-AB-B4-76-40-68-9A-26-7D-8D-6E",
+ Roundtrip (TripleDES.Create (), CipherMode.CBC), "Encrypted data");
+ }
+
+ [Test]
+ public void TripleDES_CFB ()
+ {
+ Assert.AreEqual ("89-9F-00-9D-26-BB-21-59-85-6D-A2-BF-15-FE-73-53-1F-CE-35-26-5B-DF-43-26",
+ Roundtrip (TripleDES.Create (), CipherMode.CFB), "Encrypted data");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void TripleDES_OFB ()
+ {
+ Assert.AreEqual ("not implemented in any released framework",
+ Roundtrip (TripleDES.Create (), CipherMode.OFB), "Encrypted data");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void TripleDES_CTS ()
+ {
+ Assert.AreEqual ("not implemented in any released framework",
+ Roundtrip (TripleDES.Create (), CipherMode.CTS), "Encrypted data");
+ }
+ }
+}
// CryptoConfigTest.cs - NUnit Test Cases for CryptoConfig
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
MapNameToOID ("MD5", "1.2.840.113549.2.5");
MapNameToOID ("System.Security.Cryptography.MD5", "1.2.840.113549.2.5");
MapNameToOID ("System.Security.Cryptography.MD5CryptoServiceProvider", "1.2.840.113549.2.5");
+#if NET_2_0
+ MapNameToOID ("SHA256", "2.16.840.1.101.3.4.2.1");
+ MapNameToOID ("System.Security.Cryptography.SHA256", "2.16.840.1.101.3.4.2.1");
+ MapNameToOID ("System.Security.Cryptography.SHA256Managed", "2.16.840.1.101.3.4.2.1");
+ MapNameToOID ("SHA384", "2.16.840.1.101.3.4.2.2");
+ MapNameToOID ("System.Security.Cryptography.SHA384", "2.16.840.1.101.3.4.2.2");
+ MapNameToOID ("System.Security.Cryptography.SHA384Managed", "2.16.840.1.101.3.4.2.2");
+ MapNameToOID ("SHA512", "2.16.840.1.101.3.4.2.3");
+ MapNameToOID ("System.Security.Cryptography.SHA512", "2.16.840.1.101.3.4.2.3");
+ MapNameToOID ("System.Security.Cryptography.SHA512Managed", "2.16.840.1.101.3.4.2.3");
+#else
MapNameToOID ("SHA256", "2.16.840.1.101.3.4.1");
// MapNameToOID ("SHA-256", "2.16.840.1.101.3.4.1");
MapNameToOID ("System.Security.Cryptography.SHA256", "2.16.840.1.101.3.4.1");
// MapNameToOID ("SHA-512", "2.16.840.1.101.3.4.3");
MapNameToOID ("System.Security.Cryptography.SHA512", "2.16.840.1.101.3.4.3");
MapNameToOID ("System.Security.Cryptography.SHA512Managed", "2.16.840.1.101.3.4.3");
+#endif
// LAMESPEC: only documentated in ".NET Framework Security" book
MapNameToOID ("TripleDESKeyWrap", "1.2.840.113549.1.9.16.3.6");
- // no OID defined ?
+#if NET_2_0
+ // new OID defined in Fx 2.0
+ MapNameToOID ("RSA", "1.2.840.113549.1.1.1");
+ MapNameToOID ("DSA", "1.2.840.10040.4.1");
+ MapNameToOID ("DES", "1.3.14.3.2.7");
+ MapNameToOID ("3DES", "1.2.840.113549.3.7");
+ MapNameToOID ("TripleDES", "1.2.840.113549.3.7");
+ MapNameToOID ("RC2", "1.2.840.113549.3.2");
+#else
+ // no OID defined before Fx 2.0
MapNameToOID ("RSA", null);
- MapNameToOID ("System.Security.Cryptography.RSA", null);
- MapNameToOID ("System.Security.Cryptography.AsymmetricAlgorithm", null);
MapNameToOID ("DSA", null);
- MapNameToOID ("System.Security.Cryptography.DSA", null);
MapNameToOID ("DES", null);
- MapNameToOID ("System.Security.Cryptography.DES", null);
MapNameToOID ("3DES", null);
MapNameToOID ("TripleDES", null);
+ MapNameToOID ("RC2", null);
+#endif
+ // no OID defined ?
+ MapNameToOID ("System.Security.Cryptography.RSA", null);
+ MapNameToOID ("System.Security.Cryptography.AsymmetricAlgorithm", null);
+ MapNameToOID ("System.Security.Cryptography.DSA", null);
+ MapNameToOID ("System.Security.Cryptography.DES", null);
MapNameToOID ("Triple DES", null);
MapNameToOID ("System.Security.Cryptography.TripleDES", null);
- MapNameToOID ("RC2", null);
MapNameToOID ("System.Security.Cryptography.RC2", null);
MapNameToOID ("Rijndael", null);
MapNameToOID ("System.Security.Cryptography.Rijndael", null);
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://www.novell.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
/* WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING *
[Test]
// MS BUG [ExpectedException (typeof (ObjectDisposedException))]
+#if NET_2_0
+ [ExpectedException (typeof (IndexOutOfRangeException))]
+#else
[Ignore ("Test cause System.ExecutionEngineException on MS runtime")]
+#endif
public void Read_Disposed_Break ()
{
byte[] buffer = new byte [8];
[Test]
// MS BUG [ExpectedException (typeof (ObjectDisposedException))]
+#if NET_2_0
+ [ExpectedException (typeof (IndexOutOfRangeException))]
+#else
[Ignore ("Test cause System.ExecutionEngineException on MS runtime")]
+#endif
public void Write_Disposed ()
{
byte[] buffer = new byte [8];
DES des = DES.Create ();
CryptoStream csd = new CryptoStream (debug, des.CreateDecryptor (key, iv), CryptoStreamMode.Write);
- byte[] data = new byte [64];
+ byte[] data = new byte [64] { 0xE1, 0xB2, 0x46, 0xE5, 0xA7, 0xC7, 0x4C, 0xBC, 0xD5, 0xF0, 0x8E, 0x25, 0x3B, 0xFA, 0x23, 0x80, 0x03, 0x16, 0x18, 0x17, 0xA3, 0x59, 0xBA, 0xAC, 0xFC, 0x47, 0x57, 0x2A, 0xF9, 0x44, 0x07, 0x84, 0x20, 0x74, 0x06, 0x38, 0xC2, 0xF3, 0xA1, 0xCE, 0x8C, 0x73, 0xB1, 0xE3, 0x75, 0x03, 0x66, 0x89, 0xF0, 0x4E, 0x98, 0x68, 0xB1, 0xBD, 0x85, 0x25, 0xFF, 0x4B, 0x11, 0x74, 0xEF, 0x14, 0xC8, 0xE9 };
csd.Write (data, 0, 64);
AssertEquals ("Length", 56, debug.Length);
// last block is kept for later processing
- csd.Close ();
}
}
}
--- /dev/null
+//
+// CspProviderFlagsTest.cs - NUnit Test Cases for CspProviderFlags
+//
+// Author:
+// Sebastien Pouliot <sebastien@ximian.com>
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using NUnit.Framework;
+using System;
+using System.Security.Cryptography;
+
+namespace MonoTests.System.Security.Cryptography {
+
+ [TestFixture]
+ public class CspProviderFlagsTest {
+
+ [Test]
+ public void Values ()
+ {
+#if NET_2_0
+ Assert.AreEqual ((int)CspProviderFlags.NoFlags, 0, "NoFlags");
+#endif
+ Assert.AreEqual ((int)CspProviderFlags.UseMachineKeyStore, 1, "UseMachineKeyStore");
+ Assert.AreEqual ((int)CspProviderFlags.UseDefaultKeyContainer, 2, "UseDefaultKeyContainer");
+#if NET_2_0
+ Assert.AreEqual ((int)CspProviderFlags.NoPrompt, 64, "NoPrompt");
+ Assert.AreEqual ((int)CspProviderFlags.UseArchivableKey, 16, "UseArchivableKey");
+ Assert.AreEqual ((int)CspProviderFlags.UseExistingKey, 8, "UseExistingKey");
+ Assert.AreEqual ((int)CspProviderFlags.UseNonExportableKey, 4, "UseNonExportableKey");
+ Assert.AreEqual ((int)CspProviderFlags.UseUserProtectedKey, 32, "UseUserProtectedKey");
+#endif
+ }
+
+ [Test]
+ public void Flags ()
+ {
+ CspProviderFlags cpf = CspProviderFlags.UseDefaultKeyContainer | CspProviderFlags.UseMachineKeyStore
+#if NET_2_0
+ | CspProviderFlags.NoFlags | CspProviderFlags.NoPrompt
+ | CspProviderFlags.UseArchivableKey | CspProviderFlags.UseExistingKey
+ | CspProviderFlags.UseNonExportableKey | CspProviderFlags.UseUserProtectedKey;
+
+ int expected = 127;
+#else
+ ;
+ int expected = 3;
+#endif
+ Assert.AreEqual (expected, (int)cpf, "All");
+ }
+ }
+}
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://www.novell.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
private bool machineKeyStore;
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ disposed = new DSACryptoServiceProvider (minKeySize);
+ // FX 2.0 beta 1 bug - we must use the key before clearing it
+ // http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=dc970a7f-b82f-45e5-9d37-fb0ed72e6b41
+ int ks = disposed.KeySize;
+ disposed.Clear ();
+ // do not generate a new keypair for each test
+ smallDsa = new DSACryptoServiceProvider (minKeySize);
+ }
+
[SetUp]
public void Setup ()
{
machineKeyStore = DSACryptoServiceProvider.UseMachineKeyStore;
- if (disposed == null) {
- disposed = new DSACryptoServiceProvider (minKeySize);
- disposed.Clear ();
- }
- // do not generate a new keypair for each test
- if (smallDsa == null)
- smallDsa = new DSACryptoServiceProvider (minKeySize);
}
[TearDown]
// test default key size
AssertEquals ("DSA ConstructorEmpty", 1024, dsa.KeySize);
Assert ("PersistKeyInCsp", !dsa.PersistKeyInCsp);
+#if NET_2_0
+ Assert ("PublicOnly", !dsa.PublicOnly);
+#endif
}
[Test]
// test default key size
AssertEquals ("DSA ConstructorKeySize", minKeySize, dsa.KeySize);
Assert ("PersistKeyInCsp", !dsa.PersistKeyInCsp);
+#if NET_2_0
+ Assert ("PublicOnly", !dsa.PublicOnly);
+#endif
}
[Test]
// test default key size
AssertEquals ("DSA ConstructorCspParameters", 1024, dsa.KeySize);
Assert ("PersistKeyInCsp", dsa.PersistKeyInCsp);
+#if NET_2_0
+ Assert ("PublicOnly", !dsa.PublicOnly);
+#endif
}
[Test]
dsa = new DSACryptoServiceProvider (minKeySize, csp);
AssertEquals ("DSA ConstructorCspParameters", minKeySize, dsa.KeySize);
Assert ("PersistKeyInCsp", dsa.PersistKeyInCsp);
+#if NET_2_0
+ Assert ("PublicOnly", !dsa.PublicOnly);
+#endif
}
[Test]
[Ignore ("Much too long (with MS as Mono doesn't generates the keypair unless it need it)")]
- public void KeyGeneration ()
+ public void KeyGeneration ()
{
// Test every valid key size
KeySizes LegalKeySize = dsa.LegalKeySizes [0];
for (int i = LegalKeySize.MinSize; i <= LegalKeySize.MaxSize; i += LegalKeySize.SkipSize) {
dsa = new DSACryptoServiceProvider (i);
AssertEquals ("DSA.KeySize", i, dsa.KeySize);
+#if NET_2_0
+ Assert ("PublicOnly", !dsa.PublicOnly);
+#endif
}
}
byte[] hash = new byte [20];
dsa.CreateSignature (hash); // mono generates keypair here
AssertEquals ("AfterMonoKeyGeneration.KeySize", minKeySize, dsa.KeySize);
+#if NET_2_0
+ Assert ("PublicOnly", !dsa.PublicOnly);
+#endif
}
// here Dispose is called (with true)
}
}
[Test]
+#if ! NET_2_0
[Ignore ("Running this test breaks all further DSA tests on MS runtime!")]
+#endif
public void VerifySignatureWithoutKey ()
{
byte[] hash = new byte [20];
Assert ("VerifySignature(WithoutKey)", !smallDsa.VerifySignature (hash, sign));
}
+#if NET_2_0
+ [Test]
+ public void ImportDisposed ()
+ {
+ DSACryptoServiceProvider import = new DSACryptoServiceProvider (minKeySize);
+ import.Clear ();
+ import.ImportParameters (AllTests.GetKey (false));
+ // no exception from Fx 2.0 +
+ }
+#else
[Test]
[ExpectedException (typeof (ObjectDisposedException))]
public void ImportDisposed ()
{
disposed.ImportParameters (AllTests.GetKey (false));
}
+#endif
[Test]
[ExpectedException (typeof (ObjectDisposedException))]
[Test]
[ExpectedException (typeof (CryptographicException))]
+#if ! NET_2_0
[Ignore ("MS runtime throws a System.ExecutionEngineException then exit the application")]
+#endif
public void DSAImportMissingY ()
{
DSAParameters input = AllTests.GetKey (false);
Assert ("UseMachineKeyStore", machineKeyPair != dsa.ToXmlString (true));
}
#endif
+
+#if NET_2_0
+ [Test]
+ public void CspKeyContainerInfo_NewKeypair ()
+ {
+ dsa = new DSACryptoServiceProvider (minKeySize);
+ CspKeyContainerInfo info = dsa.CspKeyContainerInfo;
+ Assert ("Accessible", !info.Accessible);
+ // info.Exportable throws a CryptographicException at this stage
+ Assert ("HardwareDevice", !info.HardwareDevice);
+ AssertNotNull ("KeyContainerName", info.KeyContainerName);
+ AssertEquals ("KeyNumber", KeyNumber.Signature, info.KeyNumber);
+ Assert ("MachineKeyStore", !info.MachineKeyStore);
+ // info.Protected throws a CryptographicException at this stage
+ AssertNotNull ("ProviderName", info.ProviderName);
+ AssertEquals ("ProviderType", 13, info.ProviderType);
+ Assert ("RandomlyGenerated", info.RandomlyGenerated);
+ Assert ("Removable", !info.Removable);
+ // info.UniqueKeyContainerName throws a CryptographicException at this stage
+ }
+
+ [Test]
+ public void CspKeyContainerInfo_ImportedKeypair ()
+ {
+ dsa = new DSACryptoServiceProvider (minKeySize);
+ DSAParameters rsap = AllTests.GetKey (true);
+ dsa.ImportParameters (rsap);
+ CspKeyContainerInfo info = dsa.CspKeyContainerInfo;
+ Assert ("Accessible", info.Accessible);
+ Assert ("Exportable", info.Exportable);
+ Assert ("HardwareDevice", !info.HardwareDevice);
+ AssertNotNull ("KeyContainerName", info.KeyContainerName);
+ AssertEquals ("KeyNumber", KeyNumber.Signature, info.KeyNumber);
+ Assert ("MachineKeyStore", !info.MachineKeyStore);
+ Assert ("Protected", !info.Protected);
+ AssertNotNull ("ProviderName", info.ProviderName);
+ AssertEquals ("ProviderType", 13, info.ProviderType);
+ Assert ("RandomlyGenerated", info.RandomlyGenerated);
+ Assert ("Removable", !info.Removable);
+ AssertNotNull ("UniqueKeyContainerName", info.UniqueKeyContainerName);
+ }
+
+ [Test]
+ public void CspKeyContainerInfo_ImportedPublicKey ()
+ {
+ dsa = new DSACryptoServiceProvider (minKeySize);
+ DSAParameters rsap = AllTests.GetKey (false);
+ dsa.ImportParameters (rsap);
+ CspKeyContainerInfo info = dsa.CspKeyContainerInfo;
+ Assert ("Accessible", !info.Accessible);
+ // info.Exportable throws a CryptographicException at this stage
+ Assert ("HardwareDevice", !info.HardwareDevice);
+ AssertNotNull ("KeyContainerName", info.KeyContainerName);
+ AssertEquals ("KeyNumber", KeyNumber.Signature, info.KeyNumber);
+ Assert ("MachineKeyStore", !info.MachineKeyStore);
+ // info.Protected throws a CryptographicException at this stage
+ AssertNotNull ("ProviderName", info.ProviderName);
+ AssertEquals ("ProviderType", 13, info.ProviderType);
+ Assert ("RandomlyGenerated", info.RandomlyGenerated);
+ Assert ("Removable", !info.Removable);
+ // info.UniqueKeyContainerName throws a CryptographicException at this stage
+ }
+
+ [Test]
+ public void ExportCspBlob_Full ()
+ {
+ dsa = new DSACryptoServiceProvider (minKeySize);
+ DSAParameters dsap = AllTests.GetKey (true);
+ dsa.ImportParameters (dsap);
+
+ byte[] keypair = dsa.ExportCspBlob (true);
+ AssertEquals ("07-02-00-00-00-22-00-00-44-53-53-32-00-04-00-00-D3-7B-C6-ED-3F-72-44-BD-22-7D-F2-D4-62-FE-7C-E3-75-8F-9C-DE-69-C0-3A-0C-E6-26-5A-46-3D-EF-0D-90-20-C6-F6-45-7C-73-E8-B9-7D-86-27-F7-97-76-C8-1C-8E-8B-CE-26-93-E6-21-53-20-93-58-25-45-1C-46-66-17-10-98-03-96-D0-E5-C8-30-80-72-B6-49-B3-82-95-B3-8D-3A-A5-E5-60-C6-42-3A-33-70-67-30-C5-1C-32-D9-EB-CF-C1-36-B3-F3-24-07-39-86-0D-E9-12-80-73-26-A7-8C-8B-8A-40-AA-51-43-8F-20-DE-D2-9C-F3-B3-51-73-83-62-A0-11-C9-50-93-E1-F0-64-BE-D0-9E-E0-5B-13-47-AA-56-65-62-47-FD-3A-94-B7-1B-E5-35-95-86-14-64-C0-D6-07-96-4C-55-1E-0A-4C-10-C2-B5-E6-FB-74-F9-A5-72-E0-42-96-62-0B-EF-B7-52-36-7D-E3-01-12-85-E6-FE-92-75-40-C2-A6-D0-9D-16-6F-C1-C7-A7-DF-48-80-A2-5D-A0-FD-84-BE-06-AC-CB-32-22-82-D2-D7-7C-69-FC-BC-94-78-2B-11-5B-1C-1E-AF-DB-7A-AA-31-F3-D8-74-84-00-3F-9D-B9-4B-B2-68-7E-F4-1B-C2-83-73-21-78-0F-D5-0F-B0-EB-76-41-F1-23-7A-6A-78-CC-4F-3D-B1-2F-0A-F6-9A-A7-18-C1-2F-F0-B7-73-91-51-6D-9B-B5-B2-03-7C-E0-00-00-00-9B-AF-1B-E9-C1-C7-35-F5-E2-EB-C9-EE-F6-BA-25-6D-6F-39-83-B9", BitConverter.ToString (keypair));
+ }
+
+ [Test]
+ public void ExportCspBlob_PublicOnly ()
+ {
+ dsa = new DSACryptoServiceProvider (minKeySize);
+ DSAParameters dsap = AllTests.GetKey (true);
+ dsa.ImportParameters (dsap);
+
+ byte[] pubkey = dsa.ExportCspBlob (false);
+ AssertEquals ("06-02-00-00-00-22-00-00-44-53-53-31-00-04-00-00-D3-7B-C6-ED-3F-72-44-BD-22-7D-F2-D4-62-FE-7C-E3-75-8F-9C-DE-69-C0-3A-0C-E6-26-5A-46-3D-EF-0D-90-20-C6-F6-45-7C-73-E8-B9-7D-86-27-F7-97-76-C8-1C-8E-8B-CE-26-93-E6-21-53-20-93-58-25-45-1C-46-66-17-10-98-03-96-D0-E5-C8-30-80-72-B6-49-B3-82-95-B3-8D-3A-A5-E5-60-C6-42-3A-33-70-67-30-C5-1C-32-D9-EB-CF-C1-36-B3-F3-24-07-39-86-0D-E9-12-80-73-26-A7-8C-8B-8A-40-AA-51-43-8F-20-DE-D2-9C-F3-B3-51-73-83-62-A0-11-C9-50-93-E1-F0-64-BE-D0-9E-E0-5B-13-47-AA-56-65-62-47-FD-3A-94-B7-1B-E5-35-95-86-14-64-C0-D6-07-96-4C-55-1E-0A-4C-10-C2-B5-E6-FB-74-F9-A5-72-E0-42-96-62-0B-EF-B7-52-36-7D-E3-01-12-85-E6-FE-92-75-40-C2-A6-D0-9D-16-6F-C1-C7-A7-DF-48-80-A2-5D-A0-FD-84-BE-06-AC-CB-32-22-82-D2-D7-7C-69-FC-BC-94-78-2B-11-5B-1C-1E-AF-DB-7A-AA-31-F3-D8-74-84-00-3F-9D-B9-4B-B2-68-7E-F4-1B-C2-83-73-21-78-0F-D5-0F-B0-EB-76-41-F1-23-7A-6A-78-CC-4F-3D-BB-C7-03-89-C4-0B-66-86-80-D5-AA-34-E8-14-71-F9-29-BE-B9-EE-34-B1-5F-A2-C8-4D-CD-CF-0E-8E-A4-2E-D4-65-8C-27-FF-C1-41-26-F9-0E-E5-11-C9-CC-3E-45-87-EC-49-BA-7C-83-91-DE-70-E8-27-1C-47-EB-1D-E2-37-62-2F-AA-5B-30-80-8B-80-00-55-F4-64-C2-BE-5A-D3-54-4A-E7-0B-95-00-F4-BA-72-CD-F8-22-E6-30-4E-F6-BD-BE-3F-00-52-7F-E2-57-5F-C0-BE-82-C0-50-07-1C-7D-89-56-49-CE-28-52-8C-11-B1-D1-51-51-12-B2-E0-00-00-00-9B-AF-1B-E9-C1-C7-35-F5-E2-EB-C9-EE-F6-BA-25-6D-6F-39-83-B9", BitConverter.ToString (pubkey));
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void ExportCspBlob_MissingPrivateKey ()
+ {
+ dsa = new DSACryptoServiceProvider (minKeySize);
+ DSAParameters dsap = AllTests.GetKey (false);
+ dsa.ImportParameters (dsap);
+
+ dsa.ExportCspBlob (true);
+ }
+
+ [Test]
+ public void ExportCspBlob_MissingPrivateKey_PublicOnly ()
+ {
+ dsa = new DSACryptoServiceProvider (minKeySize);
+ DSAParameters dsap = AllTests.GetKey (false);
+ dsa.ImportParameters (dsap);
+
+ byte[] pubkey = dsa.ExportCspBlob (false);
+ AssertEquals ("06-02-00-00-00-22-00-00-44-53-53-31-00-04-00-00-D3-7B-C6-ED-3F-72-44-BD-22-7D-F2-D4-62-FE-7C-E3-75-8F-9C-DE-69-C0-3A-0C-E6-26-5A-46-3D-EF-0D-90-20-C6-F6-45-7C-73-E8-B9-7D-86-27-F7-97-76-C8-1C-8E-8B-CE-26-93-E6-21-53-20-93-58-25-45-1C-46-66-17-10-98-03-96-D0-E5-C8-30-80-72-B6-49-B3-82-95-B3-8D-3A-A5-E5-60-C6-42-3A-33-70-67-30-C5-1C-32-D9-EB-CF-C1-36-B3-F3-24-07-39-86-0D-E9-12-80-73-26-A7-8C-8B-8A-40-AA-51-43-8F-20-DE-D2-9C-F3-B3-51-73-83-62-A0-11-C9-50-93-E1-F0-64-BE-D0-9E-E0-5B-13-47-AA-56-65-62-47-FD-3A-94-B7-1B-E5-35-95-86-14-64-C0-D6-07-96-4C-55-1E-0A-4C-10-C2-B5-E6-FB-74-F9-A5-72-E0-42-96-62-0B-EF-B7-52-36-7D-E3-01-12-85-E6-FE-92-75-40-C2-A6-D0-9D-16-6F-C1-C7-A7-DF-48-80-A2-5D-A0-FD-84-BE-06-AC-CB-32-22-82-D2-D7-7C-69-FC-BC-94-78-2B-11-5B-1C-1E-AF-DB-7A-AA-31-F3-D8-74-84-00-3F-9D-B9-4B-B2-68-7E-F4-1B-C2-83-73-21-78-0F-D5-0F-B0-EB-76-41-F1-23-7A-6A-78-CC-4F-3D-BB-C7-03-89-C4-0B-66-86-80-D5-AA-34-E8-14-71-F9-29-BE-B9-EE-34-B1-5F-A2-C8-4D-CD-CF-0E-8E-A4-2E-D4-65-8C-27-FF-C1-41-26-F9-0E-E5-11-C9-CC-3E-45-87-EC-49-BA-7C-83-91-DE-70-E8-27-1C-47-EB-1D-E2-37-62-2F-AA-5B-30-80-8B-80-00-55-F4-64-C2-BE-5A-D3-54-4A-E7-0B-95-00-F4-BA-72-CD-F8-22-E6-30-4E-F6-BD-BE-3F-00-52-7F-E2-57-5F-C0-BE-82-C0-50-07-1C-7D-89-56-49-CE-28-52-8C-11-B1-D1-51-51-12-B2-E0-00-00-00-9B-AF-1B-E9-C1-C7-35-F5-E2-EB-C9-EE-F6-BA-25-6D-6F-39-83-B9", BitConverter.ToString (pubkey));
+ }
+
+ [Test]
+ public void ImportCspBlob_Keypair ()
+ {
+ byte[] blob = new byte [336] { 0x07, 0x02, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x44, 0x53, 0x53, 0x32, 0x00, 0x04, 0x00, 0x00, 0xD3, 0x7B, 0xC6, 0xED, 0x3F, 0x72, 0x44, 0xBD, 0x22, 0x7D, 0xF2, 0xD4, 0x62, 0xFE, 0x7C, 0xE3, 0x75, 0x8F, 0x9C, 0xDE, 0x69, 0xC0, 0x3A, 0x0C, 0xE6, 0x26, 0x5A, 0x46, 0x3D, 0xEF, 0x0D, 0x90, 0x20, 0xC6, 0xF6, 0x45, 0x7C, 0x73, 0xE8, 0xB9, 0x7D, 0x86, 0x27, 0xF7, 0x97, 0x76, 0xC8, 0x1C, 0x8E, 0x8B, 0xCE, 0x26, 0x93, 0xE6, 0x21, 0x53, 0x20, 0x93, 0x58, 0x25, 0x45, 0x1C, 0x46, 0x66, 0x17, 0x10, 0x98, 0x03, 0x96, 0xD0, 0xE5, 0xC8, 0x30, 0x80, 0x72, 0xB6, 0x49, 0xB3, 0x82, 0x95, 0xB3, 0x8D, 0x3A, 0xA5, 0xE5, 0x60, 0xC6, 0x42, 0x3A, 0x33, 0x70, 0x67, 0x30, 0xC5, 0x1C, 0x32, 0xD9, 0xEB, 0xCF, 0xC1, 0x36, 0xB3, 0xF3, 0x24, 0x07, 0x39, 0x86, 0x0D, 0xE9, 0x12, 0x80, 0x73, 0x26, 0xA7, 0x8C, 0x8B, 0x8A, 0x40, 0xAA, 0x51, 0x43, 0x8F, 0x20, 0xDE, 0xD2, 0x9C, 0xF3, 0xB3, 0x51, 0x73, 0x83, 0x62, 0xA0, 0x11, 0xC9, 0x50, 0x93, 0xE1, 0xF0, 0x64, 0xBE, 0xD0, 0x9E, 0xE0, 0x5B, 0x13, 0x47, 0xAA, 0x56, 0x65, 0x62, 0x47, 0xFD, 0x3A, 0x94, 0xB7, 0x1B, 0xE5, 0x35, 0x95, 0x86, 0x14, 0x64, 0xC0, 0xD6, 0x07, 0x96, 0x4C, 0x55, 0x1E, 0x0A, 0x4C, 0x10, 0xC2, 0xB5, 0xE6, 0xFB, 0x74, 0xF9, 0xA5, 0x72, 0xE0, 0x42, 0x96, 0x62, 0x0B, 0xEF, 0xB7, 0x52, 0x36, 0x7D, 0xE3, 0x01, 0x12, 0x85, 0xE6, 0xFE, 0x92, 0x75, 0x40, 0xC2, 0xA6, 0xD0, 0x9D, 0x16, 0x6F, 0xC1, 0xC7, 0xA7, 0xDF, 0x48, 0x80, 0xA2, 0x5D, 0xA0, 0xFD, 0x84, 0xBE, 0x06, 0xAC, 0xCB, 0x32, 0x22, 0x82, 0xD2, 0xD7, 0x7C, 0x69, 0xFC, 0xBC, 0x94, 0x78, 0x2B, 0x11, 0x5B, 0x1C, 0x1E, 0xAF, 0xDB, 0x7A, 0xAA, 0x31, 0xF3, 0xD8, 0x74, 0x84, 0x00, 0x3F, 0x9D, 0xB9, 0x4B, 0xB2, 0x68, 0x7E, 0xF4, 0x1B, 0xC2, 0x83, 0x73, 0x21, 0x78, 0x0F, 0xD5, 0x0F, 0xB0, 0xEB, 0x76, 0x41, 0xF1, 0x23, 0x7A, 0x6A, 0x78, 0xCC, 0x4F, 0x3D, 0xB1, 0x2F, 0x0A, 0xF6, 0x9A, 0xA7, 0x18, 0xC1, 0x2F, 0xF0, 0xB7, 0x73, 0x91, 0x51, 0x6D, 0x9B, 0xB5, 0xB2, 0x03, 0x7C, 0xE0, 0x00, 0x00, 0x00, 0x9B, 0xAF, 0x1B, 0xE9, 0xC1, 0xC7, 0x35, 0xF5, 0xE2, 0xEB, 0xC9, 0xEE, 0xF6, 0xBA, 0x25, 0x6D, 0x6F, 0x39, 0x83, 0xB9 };
+ dsa = new DSACryptoServiceProvider (minKeySize);
+ dsa.ImportCspBlob (blob);
+
+ byte[] keypair = dsa.ExportCspBlob (true);
+ for (int i = 0; i < blob.Length; i++)
+ AssertEquals (i.ToString (), blob [i], keypair [i]);
+ }
+
+ [Test]
+ public void ExportCspBlob_PublicKey ()
+ {
+ byte[] blob = new byte [444] { 0x06, 0x02, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x44, 0x53, 0x53, 0x31, 0x00, 0x04, 0x00, 0x00, 0xD3, 0x7B, 0xC6, 0xED, 0x3F, 0x72, 0x44, 0xBD, 0x22, 0x7D, 0xF2, 0xD4, 0x62, 0xFE, 0x7C, 0xE3, 0x75, 0x8F, 0x9C, 0xDE, 0x69, 0xC0, 0x3A, 0x0C, 0xE6, 0x26, 0x5A, 0x46, 0x3D, 0xEF, 0x0D, 0x90, 0x20, 0xC6, 0xF6, 0x45, 0x7C, 0x73, 0xE8, 0xB9, 0x7D, 0x86, 0x27, 0xF7, 0x97, 0x76, 0xC8, 0x1C, 0x8E, 0x8B, 0xCE, 0x26, 0x93, 0xE6, 0x21, 0x53, 0x20, 0x93, 0x58, 0x25, 0x45, 0x1C, 0x46, 0x66, 0x17, 0x10, 0x98, 0x03, 0x96, 0xD0, 0xE5, 0xC8, 0x30, 0x80, 0x72, 0xB6, 0x49, 0xB3, 0x82, 0x95, 0xB3, 0x8D, 0x3A, 0xA5, 0xE5, 0x60, 0xC6, 0x42, 0x3A, 0x33, 0x70, 0x67, 0x30, 0xC5, 0x1C, 0x32, 0xD9, 0xEB, 0xCF, 0xC1, 0x36, 0xB3, 0xF3, 0x24, 0x07, 0x39, 0x86, 0x0D, 0xE9, 0x12, 0x80, 0x73, 0x26, 0xA7, 0x8C, 0x8B, 0x8A, 0x40, 0xAA, 0x51, 0x43, 0x8F, 0x20, 0xDE, 0xD2, 0x9C, 0xF3, 0xB3, 0x51, 0x73, 0x83, 0x62, 0xA0, 0x11, 0xC9, 0x50, 0x93, 0xE1, 0xF0, 0x64, 0xBE, 0xD0, 0x9E, 0xE0, 0x5B, 0x13, 0x47, 0xAA, 0x56, 0x65, 0x62, 0x47, 0xFD, 0x3A, 0x94, 0xB7, 0x1B, 0xE5, 0x35, 0x95, 0x86, 0x14, 0x64, 0xC0, 0xD6, 0x07, 0x96, 0x4C, 0x55, 0x1E, 0x0A, 0x4C, 0x10, 0xC2, 0xB5, 0xE6, 0xFB, 0x74, 0xF9, 0xA5, 0x72, 0xE0, 0x42, 0x96, 0x62, 0x0B, 0xEF, 0xB7, 0x52, 0x36, 0x7D, 0xE3, 0x01, 0x12, 0x85, 0xE6, 0xFE, 0x92, 0x75, 0x40, 0xC2, 0xA6, 0xD0, 0x9D, 0x16, 0x6F, 0xC1, 0xC7, 0xA7, 0xDF, 0x48, 0x80, 0xA2, 0x5D, 0xA0, 0xFD, 0x84, 0xBE, 0x06, 0xAC, 0xCB, 0x32, 0x22, 0x82, 0xD2, 0xD7, 0x7C, 0x69, 0xFC, 0xBC, 0x94, 0x78, 0x2B, 0x11, 0x5B, 0x1C, 0x1E, 0xAF, 0xDB, 0x7A, 0xAA, 0x31, 0xF3, 0xD8, 0x74, 0x84, 0x00, 0x3F, 0x9D, 0xB9, 0x4B, 0xB2, 0x68, 0x7E, 0xF4, 0x1B, 0xC2, 0x83, 0x73, 0x21, 0x78, 0x0F, 0xD5, 0x0F, 0xB0, 0xEB, 0x76, 0x41, 0xF1, 0x23, 0x7A, 0x6A, 0x78, 0xCC, 0x4F, 0x3D, 0xBB, 0xC7, 0x03, 0x89, 0xC4, 0x0B, 0x66, 0x86, 0x80, 0xD5, 0xAA, 0x34, 0xE8, 0x14, 0x71, 0xF9, 0x29, 0xBE, 0xB9, 0xEE, 0x34, 0xB1, 0x5F, 0xA2, 0xC8, 0x4D, 0xCD, 0xCF, 0x0E, 0x8E, 0xA4, 0x2E, 0xD4, 0x65, 0x8C, 0x27, 0xFF, 0xC1, 0x41, 0x26, 0xF9, 0x0E, 0xE5, 0x11, 0xC9, 0xCC, 0x3E, 0x45, 0x87, 0xEC, 0x49, 0xBA, 0x7C, 0x83, 0x91, 0xDE, 0x70, 0xE8, 0x27, 0x1C, 0x47, 0xEB, 0x1D, 0xE2, 0x37, 0x62, 0x2F, 0xAA, 0x5B, 0x30, 0x80, 0x8B, 0x80, 0x00, 0x55, 0xF4, 0x64, 0xC2, 0xBE, 0x5A, 0xD3, 0x54, 0x4A, 0xE7, 0x0B, 0x95, 0x00, 0xF4, 0xBA, 0x72, 0xCD, 0xF8, 0x22, 0xE6, 0x30, 0x4E, 0xF6, 0xBD, 0xBE, 0x3F, 0x00, 0x52, 0x7F, 0xE2, 0x57, 0x5F, 0xC0, 0xBE, 0x82, 0xC0, 0x50, 0x07, 0x1C, 0x7D, 0x89, 0x56, 0x49, 0xCE, 0x28, 0x52, 0x8C, 0x11, 0xB1, 0xD1, 0x51, 0x51, 0x12, 0xB2, 0xE0, 0x00, 0x00, 0x00, 0x9B, 0xAF, 0x1B, 0xE9, 0xC1, 0xC7, 0x35, 0xF5, 0xE2, 0xEB, 0xC9, 0xEE, 0xF6, 0xBA, 0x25, 0x6D, 0x6F, 0x39, 0x83, 0xB9 };
+ dsa = new DSACryptoServiceProvider (minKeySize);
+ dsa.ImportCspBlob (blob);
+
+ byte[] pubkey = dsa.ExportCspBlob (false);
+ for (int i = 0; i < blob.Length; i++)
+ AssertEquals (i.ToString (), blob [i], pubkey [i]);
+ }
+
+ [Test]
+// [ExpectedException (typeof (ArgumentNullException))]
+// http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=2b7ff7d4-67db-43f0-8eba-20d962708140
+ [ExpectedException (typeof (NullReferenceException))]
+ public void ImportCspBlob_Null ()
+ {
+ dsa = new DSACryptoServiceProvider (minKeySize);
+ dsa.ImportCspBlob (null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void ImportCspBlob_Bad ()
+ {
+ byte[] blob = new byte [148]; // valid size for public key
+ dsa = new DSACryptoServiceProvider (minKeySize);
+ dsa.ImportCspBlob (blob);
+ }
+#endif
}
}
// DSASignatureDeformatterTest.cs - NUnit Test Cases for DSASignatureDeformatter
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2002 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
namespace MonoTests.System.Security.Cryptography {
-public class DSASignatureDeformatterTest : TestCase {
+[TestFixture]
+public class DSASignatureDeformatterTest {
protected DSASignatureDeformatter def;
protected static DSA dsa;
protected static RSA rsa;
- protected override void SetUp ()
+ static byte[] hash = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13 };
+ static byte[] sign = { 0x50, 0xd2, 0xb0, 0x8b, 0xcd, 0x5e, 0xb2, 0xc2, 0x35, 0x82, 0xd3, 0x76, 0x07, 0x79, 0xbb, 0x55, 0x98, 0x72, 0x43, 0xe8,
+ 0x74, 0xc9, 0x35, 0xf8, 0xc9, 0xbd, 0x69, 0x2f, 0x08, 0x34, 0xfa, 0x5a, 0x59, 0x23, 0x2a, 0x85, 0x7b, 0xa3, 0xb3, 0x82 };
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
{
- def = new DSASignatureDeformatter ();
// key generation is VERY long so one time is enough
- if (dsa == null)
- dsa = DSA.Create ();
- if (rsa == null)
- rsa = RSA.Create ();
+ dsa = DSA.Create ();
+ rsa = RSA.Create ();
}
- protected override void TearDown () {}
+ [SetUp]
+ public void SetUp ()
+ {
+ def = new DSASignatureDeformatter ();
+ }
- public void TestConstructors ()
+ [Test]
+ public void Constructor_Empty ()
{
- // empty constructor
DSASignatureDeformatter def = new DSASignatureDeformatter ();
- AssertNotNull ("DSASignatureDeformatter()", def);
- // AsymmetricAlgorithm constructor (with null)
- def = new DSASignatureDeformatter (null);
- AssertNotNull ("DSASignatureDeformatter(null)", def);
- // AsymmetricAlgorithm constructor (with DSA)
- def = new DSASignatureDeformatter (dsa);
- AssertNotNull ("DSASignatureDeformatter(dsa)", def);
- // AsymmetricAlgorithm constructor (with RSA)
- try {
- def = new DSASignatureDeformatter (rsa);
- Fail ("Expected InvalidCastException but got none");
- }
- catch (InvalidCastException) {
- // this is expected
- }
- catch (Exception e) {
- Fail ("Expected InvalidCastException but got " + e.ToString ());
- }
- }
-
- // Method is documented as unused so...
- public void TestSetHash ()
- {
- // null is ok
- try {
- def.SetHashAlgorithm (null);
- }
- catch (ArgumentNullException) {
- // do nothing, this is what we expect
- }
- catch (Exception e) {
- Fail ("Expected ArgumentNullException but got " + e.ToString ());
- }
- // SHA1
- try {
- def.SetHashAlgorithm ("SHA1");
- }
- catch (Exception e) {
- Fail ("Unexpected exception: " + e.ToString ());
- }
- // MD5 (bad)
- try {
- def.SetHashAlgorithm ("MD5");
- }
- catch (CryptographicUnexpectedOperationException) {
- // do nothing, this is what we expect
- }
- catch (Exception e) {
- Fail ("Expected CryptographicUnexpectedOperationException but got " + e.ToString ());
- }
- }
-
- public void TestSetKey ()
- {
- // here null is ok
- try {
- def.SetKey (null);
- }
- catch (Exception e) {
- Fail ("Unexpected exception: " + e.ToString ());
- }
- // RSA (bad)
- try {
- def.SetKey (rsa);
- Fail ("Expected InvalidCastException but got none");
- }
- catch (InvalidCastException) {
- // do nothing, this is what we expect
- }
- catch (Exception e) {
- Fail ("Expected InvalidCastException but got: " + e.ToString ());
- }
- // DSA
- try {
- def.SetKey (dsa);
- }
- catch (Exception e) {
- Fail ("Unexpected exception: " + e.ToString ());
- }
- }
-
- public void TestVerify ()
- {
- byte[] hash = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13 };
- byte[] sign = { 0x50, 0xd2, 0xb0, 0x8b, 0xcd, 0x5e, 0xb2, 0xc2, 0x35, 0x82, 0xd3, 0x76, 0x07, 0x79, 0xbb, 0x55, 0x98, 0x72, 0x43, 0xe8,
- 0x74, 0xc9, 0x35, 0xf8, 0xc9, 0xbd, 0x69, 0x2f, 0x08, 0x34, 0xfa, 0x5a, 0x59, 0x23, 0x2a, 0x85, 0x7b, 0xa3, 0xb3, 0x82 };
- bool ok = false;
- try {
- ok = def.VerifySignature (hash, sign);
- }
- catch (CryptographicUnexpectedOperationException) {
- // do nothing, this is what we expect
- }
- catch (Exception e) {
- Fail ("Expected CryptographicUnexpectedOperationException but got " + e.ToString ());
- }
+ Assert.IsNotNull (def);
+ }
+
+ [Test]
+#if NET_2_0
+ [ExpectedException (typeof (ArgumentNullException))]
+#endif
+ public void Constructor_Null ()
+ {
+ DSASignatureDeformatter def = new DSASignatureDeformatter (null);
+ Assert.IsNotNull (def);
+ }
+
+ [Test]
+ public void Constructor_DSA ()
+ {
+ DSASignatureDeformatter def = new DSASignatureDeformatter (dsa);
+ Assert.IsNotNull (def);
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidCastException))]
+ public void Constructor_RSA ()
+ {
+ DSASignatureDeformatter def = new DSASignatureDeformatter (rsa);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void SetHash_Null ()
+ {
+ def.SetHashAlgorithm (null);
+ }
+
+ [Test]
+ public void SetHash_SHA1 ()
+ {
+ def.SetHashAlgorithm ("SHA1");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicUnexpectedOperationException))]
+ public void SetHash_MD5 ()
+ {
+ def.SetHashAlgorithm ("MD5");
+ }
+
+ [Test]
+#if NET_2_0
+ [ExpectedException (typeof (ArgumentNullException))]
+#endif
+ public void SetKey_Null ()
+ {
+ def.SetKey (null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidCastException))]
+ public void SetKey_RSA ()
+ {
+ def.SetKey (rsa);
+ }
+
+ [Test]
+ public void SetKey_DSA ()
+ {
+ def.SetKey (dsa);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicUnexpectedOperationException))]
+ public void Verify_NoKeyPair ()
+ {
+ def.VerifySignature (hash, sign);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void Verify_NullSignature ()
+ {
+ dsa.ImportParameters (AllTests.GetKey (false));
+ def.SetKey (dsa);
+ def.VerifySignature (hash, null);
+ }
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void Verify_NullHash ()
+ {
dsa.ImportParameters (AllTests.GetKey (false));
def.SetKey (dsa);
+ byte[] s = null; // overloaded method
+ def.VerifySignature (s, sign);
+ }
- // missing signature
- try {
- ok = def.VerifySignature (hash, null);
- Fail ("Expected ArgumentNullException but got none");
- }
- catch (ArgumentNullException) {
- // do nothing, this is what we expect
- }
- catch (Exception e) {
- Fail ("Expected ArgumentNullException but got " + e.ToString ());
- }
-
- // missing hash
- try {
- byte[] s = null; // overloaded method
- ok = def.VerifySignature (s, sign);
- Fail ("Expected ArgumentNullException but got none");
- }
- catch (ArgumentNullException) {
- // do nothing, this is what we expect
- }
- catch (Exception e) {
- Fail ("Expected ArgumentNullException but got " + e.ToString ());
- }
-
- ok = def.VerifySignature (hash, sign);
- Assert ("verified signature", ok);
+ [Test]
+ public void Verify ()
+ {
+ dsa.ImportParameters (AllTests.GetKey (false));
+ def.SetKey (dsa);
+ Assert.IsTrue (def.VerifySignature (hash, sign));
+ }
+ [Test]
+ public void Verify_Bad ()
+ {
+ dsa.ImportParameters (AllTests.GetKey (false));
+ def.SetKey (dsa);
byte[] badSign = { 0x49, 0xd2, 0xb0, 0x8b, 0xcd, 0x5e, 0xb2, 0xc2, 0x35, 0x82, 0xd3, 0x76, 0x07, 0x79, 0xbb, 0x55, 0x98, 0x72, 0x43, 0xe8,
- 0x74, 0xc9, 0x35, 0xf8, 0xc9, 0xbd, 0x69, 0x2f, 0x08, 0x34, 0xfa, 0x5a, 0x59, 0x23, 0x2a, 0x85, 0x7b, 0xa3, 0xb3, 0x82 };
- ok = def.VerifySignature (hash, badSign);
- Assert ("didn't verified bad signature", !ok);
+ 0x74, 0xc9, 0x35, 0xf8, 0xc9, 0xbd, 0x69, 0x2f, 0x08, 0x34, 0xfa, 0x5a, 0x59, 0x23, 0x2a, 0x85, 0x7b, 0xa3, 0xb3, 0x82 };
+ Assert.IsFalse (def.VerifySignature (hash, badSign));
}
}
// DSASignatureFormatterTest.cs - NUnit Test Cases for DSASignatureFormatter
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2002 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
namespace MonoTests.System.Security.Cryptography {
-public class DSASignatureFormatterTest : TestCase {
+[TestFixture]
+public class DSASignatureFormatterTest {
protected DSASignatureFormatter fmt;
protected static DSA dsa;
protected static RSA rsa;
- protected override void SetUp ()
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
{
- fmt = new DSASignatureFormatter ();
// key generation is VERY long so one time is enough
- if (dsa == null)
- dsa = DSA.Create ();
- if (rsa == null)
- rsa = RSA.Create ();
+ dsa = DSA.Create ();
+ rsa = RSA.Create ();
}
- protected override void TearDown () {}
+ [SetUp]
+ public void SetUp ()
+ {
+ fmt = new DSASignatureFormatter ();
+ }
- public void TestConstructors ()
+ [Test]
+ public void Constructor_Empty ()
{
- // empty constructor
DSASignatureFormatter fmt = new DSASignatureFormatter ();
- AssertNotNull ("DSASignatureFormatter()", fmt);
- // AsymmetricAlgorithm constructor (with null)
- fmt = new DSASignatureFormatter (null);
- AssertNotNull ("DSASignatureFormatter(null)", fmt);
- // AsymmetricAlgorithm constructor (with DSA)
- fmt = new DSASignatureFormatter (dsa);
- AssertNotNull ("DSASignatureFormatter(dsa)", fmt);
- // AsymmetricAlgorithm constructor (with RSA)
- try {
- fmt = new DSASignatureFormatter (rsa);
- Fail ("Expected InvalidCastException but got none");
- }
- catch (InvalidCastException) {
- // this is expected
- }
- catch (Exception e) {
- Fail ("Expected InvalidCastException but got " + e.ToString ());
- }
- }
-
- public void TestSetHash ()
- {
- // null is ok
- try {
- fmt.SetHashAlgorithm (null);
- }
- catch (ArgumentNullException) {
- // do nothing, this is what we expect
- }
- catch (Exception e) {
- Fail ("Expected ArgumentNullException but got " + e.ToString ());
- }
- // SHA1
- try {
- fmt.SetHashAlgorithm ("SHA1");
- }
- catch (Exception e) {
- Fail ("Unexpected exception: " + e.ToString ());
- }
- // MD5 (bad)
- try {
- fmt.SetHashAlgorithm ("MD5");
- }
- catch (CryptographicUnexpectedOperationException) {
- // do nothing, this is what we expect
- }
- catch (Exception e) {
- Fail ("Expected CryptographicUnexpectedOperationException but got " + e.ToString ());
- }
- }
-
- public void TestSetKey () {
- // here null is ok
- try {
- fmt.SetKey (null);
- }
- catch (Exception e) {
- Fail ("Unexpected exception: " + e.ToString ());
- }
- // RSA (bad)
- try {
- fmt.SetKey (rsa);
- Fail ("Expected InvalidCastException but got none");
- }
- catch (InvalidCastException) {
- // do nothing, this is what we expect
- }
- catch (Exception e) {
- Fail ("Expected InvalidCastException but got: " + e.ToString ());
- }
- // DSA
- try {
- fmt.SetKey (dsa);
- }
- catch (Exception e) {
- Fail ("Unexpected exception: " + e.ToString ());
- }
+ Assert.IsNotNull (fmt);
+ }
+
+ [Test]
+ public void Constructor_DSA ()
+ {
+ DSASignatureFormatter fmt = new DSASignatureFormatter (dsa);
+ Assert.IsNotNull (fmt);
+ }
+
+ [Test]
+#if NET_2_0
+ [ExpectedException (typeof (ArgumentNullException))]
+#endif
+ public void Constructor_Null ()
+ {
+ DSASignatureFormatter fmt = new DSASignatureFormatter (null);
+ Assert.IsNotNull (fmt);
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidCastException))]
+ public void Constructor_RSA ()
+ {
+ DSASignatureFormatter fmt = new DSASignatureFormatter (rsa);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void SetHash_Null ()
+ {
+ fmt.SetHashAlgorithm (null);
+ }
+
+ [Test]
+ public void SetHash_SHA1 ()
+ {
+ fmt.SetHashAlgorithm ("SHA1");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicUnexpectedOperationException))]
+ public void SetHash_MD5 ()
+ {
+ fmt.SetHashAlgorithm ("MD5");
+ }
+
+ [Test]
+#if NET_2_0
+ [ExpectedException (typeof (ArgumentNullException))]
+#endif
+ public void SetKey_Null ()
+ {
+ fmt.SetKey (null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidCastException))]
+ public void SetKey_RSA ()
+ {
+ fmt.SetKey (rsa);
+ }
+
+ [Test]
+ public void SetKey_DSA ()
+ {
+ fmt.SetKey (dsa);
}
// note: There's a bug in MS Framework where you can't re-import a key into
// the same object
- public void TestSignature ()
+
+ [Test]
+ [ExpectedException (typeof (CryptographicUnexpectedOperationException))]
+ public void Signature_NoKeyPair ()
+ {
+ byte[] hash = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13 };
+ byte[] sign = fmt.CreateSignature (hash);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void Signature_OnlyPublicKey ()
{
byte[] hash = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13 };
- byte[] sign = null;
- // no keypair
- try {
- sign = fmt.CreateSignature (hash);
- }
- catch (CryptographicUnexpectedOperationException) {
- // do nothing, this is what we expect
- }
- catch (Exception e) {
- Fail ("Expected CryptographicUnexpectedOperationException but got " + e.ToString ());
- }
-
- // try a keypair without the private key
dsa.ImportParameters (AllTests.GetKey (false));
fmt.SetKey (dsa);
- try {
- sign = fmt.CreateSignature (hash);
- Fail ("Expected CryptographicException but got none");
- }
- catch (CryptographicException) {
- // do nothing, this is what we expect
- }
- catch (Exception e) {
- Fail ("Expected CryptographicException but got " + e.ToString ());
- }
-
- // complete keypair
+ byte[] sign = fmt.CreateSignature (hash);
+ }
+
+ [Test]
+ public void Signature ()
+ {
+ byte[] hash = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13 };
+ dsa.ImportParameters (AllTests.GetKey (true));
+ fmt.SetKey (dsa);
+ byte[] sign = fmt.CreateSignature (hash);
+ Assert.IsTrue (dsa.VerifySignature (hash, sign));
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void Signature_NullHash ()
+ {
+ byte[] hash = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13 };
dsa.ImportParameters (AllTests.GetKey (true));
fmt.SetKey (dsa);
- // null hash
- try {
- byte[] h = null; // overloaded method
- sign = fmt.CreateSignature (h);
- Fail ("Expected ArgumentNullException but got none");
- }
- catch (ArgumentNullException) {
- // do nothing, this is what we expect
- }
- catch (Exception e) {
- Fail ("Expected ArgumentNullException but got " + e.ToString ());
- }
-
- // valid
- sign = fmt.CreateSignature (hash);
- Assert ("verified signature", dsa.VerifySignature (hash, sign));
+ byte[] h = null; // overloaded method
+ byte[] sign = fmt.CreateSignature (h);
}
}
// http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot (sebastien@ximian.com)
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
public void HMACRIPEMD160_d (string testName, HMACRIPEMD160 hmac, byte[] input, byte[] result)
{
- byte[] output = hmac.TransformFinalBlock (input, 0, input.Length);
- AssertEquals (testName + ".d.1", input, output);
- AssertEquals (testName + ".d.2", result, hmac.Hash);
+ hmac.TransformFinalBlock (input, 0, input.Length);
+ AssertEquals (testName + ".d", result, hmac.Hash);
// required or next operation will still return old hash
hmac.Initialize ();
}
byte[] copy = new byte [input.Length];
for (int i=0; i < input.Length - 1; i++)
hmac.TransformBlock (input, i, 1, copy, i);
- byte[] output = hmac.TransformFinalBlock (input, input.Length - 1, 1);
- AssertEquals (testName + ".e.1", input [input.Length - 1], output [0]);
- AssertEquals (testName + ".e.2", result, hmac.Hash);
+ hmac.TransformFinalBlock (input, input.Length - 1, 1);
+ AssertEquals (testName + ".e", result, hmac.Hash);
// required or next operation will still return old hash
hmac.Initialize ();
}
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell http://www.novell.com
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
public class HMACSHA1Test : KeyedHashAlgorithmTest {
-// protected HMACSHA1 hash;
+ protected HMACSHA1 algo;
[Test]
public void Constructors ()
{
- hash = new HMACSHA1 ();
+ algo = new HMACSHA1 ();
AssertNotNull ("HMACSHA1 ()", hash);
byte[] key = new byte [8];
- hash = new HMACSHA1 (key);
+ algo = new HMACSHA1 (key);
AssertNotNull ("HMACSHA1 (key)", hash);
}
[ExpectedException (typeof (NullReferenceException))]
public void Constructor_Null ()
{
- hash = new HMACSHA1 (null);
+ algo = new HMACSHA1 (null);
}
[Test]
public void Invariants ()
{
- hash = new HMACSHA1 ();
- AssertEquals ("HMACSHA1.CanReuseTransform", true, hash.CanReuseTransform);
- AssertEquals ("HMACSHA1.CanTransformMultipleBlocks", true, hash.CanTransformMultipleBlocks);
- AssertEquals ("HMACSHA1.HashName", "SHA1", (hash as HMACSHA1).HashName);
- AssertEquals ("HMACSHA1.HashSize", 160, hash.HashSize);
- AssertEquals ("HMACSHA1.InputBlockSize", 1, hash.InputBlockSize);
- AssertEquals ("HMACSHA1.OutputBlockSize", 1, hash.OutputBlockSize);
- AssertEquals ("HMACSHA1.ToString()", "System.Security.Cryptography.HMACSHA1", hash.ToString ());
+ algo = new HMACSHA1 ();
+ AssertEquals ("HMACSHA1.CanReuseTransform", true, algo.CanReuseTransform);
+ AssertEquals ("HMACSHA1.CanTransformMultipleBlocks", true, algo.CanTransformMultipleBlocks);
+ AssertEquals ("HMACSHA1.HashName", "SHA1", algo.HashName);
+ AssertEquals ("HMACSHA1.HashSize", 160, algo.HashSize);
+ AssertEquals ("HMACSHA1.InputBlockSize", 1, algo.InputBlockSize);
+ AssertEquals ("HMACSHA1.OutputBlockSize", 1, algo.OutputBlockSize);
+ AssertEquals ("HMACSHA1.ToString()", "System.Security.Cryptography.HMACSHA1", algo.ToString ());
}
-#if (NET_1_0 || NET_1_1)
- // this is legal in .NET 1.2 because HMACSHA1 derives from HMAC
+#if ! NET_2_0
+ // this is legal in .NET 2.0 because HMACSHA1 derives from HMAC
[Test]
[ExpectedException (typeof (InvalidCastException))]
public void Exceptions ()
{
- hash = new HMACSHA1 ();
- (hash as HMACSHA1).HashName = "MD5";
+ algo = new HMACSHA1 ();
+ algo.HashName = "MD5";
byte[] data = Encoding.Default.GetBytes ("MD5");
byte[] hmac = hash.ComputeHash (data);
Fail ("Expected InvalidCastException but got none");
public void CheckA (string testName, byte[] key, byte[] data, byte[] result)
{
- hash = new HMACSHA1 ();
- (hash as HMACSHA1).Key = key;
- byte[] hmac = hash.ComputeHash (data);
+ algo = new HMACSHA1 (key);
+ byte[] hmac = algo.ComputeHash (data);
AssertEquals (testName + "a1", result, hmac);
- AssertEquals (testName + "a2", result, hash.Hash);
+ AssertEquals (testName + "a2", result, algo.Hash);
}
public void CheckB (string testName, byte[] key, byte[] data, byte[] result)
{
- hash = new HMACSHA1 ();
- (hash as HMACSHA1).Key = key;
- byte[] hmac = hash.ComputeHash (data, 0, data.Length);
+ algo = new HMACSHA1 (key);
+ byte[] hmac = algo.ComputeHash (data, 0, data.Length);
AssertEquals (testName + "b1", result, hmac);
- AssertEquals (testName + "b2", result, hash.Hash);
+ AssertEquals (testName + "b2", result, algo.Hash);
}
public void CheckC (string testName, byte[] key, byte[] data, byte[] result)
{
- hash = new HMACSHA1 ();
- (hash as HMACSHA1).Key = key;
+ algo = new HMACSHA1 (key);
MemoryStream ms = new MemoryStream (data);
- byte[] hmac = hash.ComputeHash (ms);
+ byte[] hmac = algo.ComputeHash (ms);
AssertEquals (testName + "c1", result, hmac);
- AssertEquals (testName + "c2", result, hash.Hash);
+ AssertEquals (testName + "c2", result, algo.Hash);
}
public void CheckD (string testName, byte[] key, byte[] data, byte[] result)
{
- hash = new HMACSHA1 ();
- (hash as HMACSHA1).Key = key;
+ algo = new HMACSHA1 (key);
// LAMESPEC or FIXME: TransformFinalBlock doesn't return HashValue !
- hash.TransformFinalBlock (data, 0, data.Length);
- AssertEquals (testName + "d", result, hash.Hash);
+ algo.TransformFinalBlock (data, 0, data.Length);
+ AssertEquals (testName + "d", result, algo.Hash);
}
public void CheckE (string testName, byte[] key, byte[] data, byte[] result)
{
- hash = new HMACSHA1 ();
- (hash as HMACSHA1).Key = key;
+ algo = new HMACSHA1 (key);
byte[] copy = new byte [data.Length];
// LAMESPEC or FIXME: TransformFinalBlock doesn't return HashValue !
for (int i=0; i < data.Length - 1; i++)
- hash.TransformBlock (data, i, 1, copy, i);
- hash.TransformFinalBlock (data, data.Length - 1, 1);
- AssertEquals (testName + "e", result, hash.Hash);
+ algo.TransformBlock (data, i, 1, copy, i);
+ algo.TransformFinalBlock (data, data.Length - 1, 1);
+ AssertEquals (testName + "e", result, algo.Hash);
}
[Test]
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell http://www.novell.com
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
[Test]
[ExpectedException (typeof (ArgumentNullException))]
+#if ! NET_2_0
[Ignore ("System.ExecutionEngineException on MS runtime (1.1)")]
+#endif
public void TransformBlock_OutputBuffer_Null ()
{
byte[] input = new byte [8];
}
[Test]
+#if NET_2_0
+ [ExpectedException (typeof (ArgumentOutOfRangeException))]
+#else
[ExpectedException (typeof (IndexOutOfRangeException))]
+#endif
public void TransformBlock_OutputOffset_Negative ()
{
byte[] input = new byte [8];
}
[Test]
+#if NET_2_0
+ [ExpectedException (typeof (ArgumentException))]
+#else
[ExpectedException (typeof (IndexOutOfRangeException))]
+#endif
public void TransformBlock_OutputOffset_Overflow ()
{
byte[] input = new byte [8];
// MACTripleDESTest.cs - NUnit Test Cases for MACTripleDES
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot (sebastien@ximian.com)
//
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
public void ExactlyOneBlockSize ()
{
byte[] key = CombineKeys (key1, key2, key3);
-#if NET_1_0
+#if NET_1_1
+ byte [] expected = { 0x86, 0xE9, 0x65, 0xBD, 0x1E, 0xC4, 0x44, 0x61 };
+#else
// Believe it or not, MACTripleDES returns different values in 1.1
byte[] expected = { 0x23, 0xD6, 0x92, 0xA0, 0x80, 0x6E, 0xC9, 0x30 };
-#else
- byte[] expected = { 0x86, 0xE9, 0x65, 0xBD, 0x1E, 0xC4, 0x44, 0x61 };
#endif
byte[] data = new byte [8];
Check ("3DESMAC-A2", key, data, expected);
public void ExactMultipleBlockSize ()
{
byte[] key = CombineKeys (key1, key2, key3);
-#if NET_1_0
+#if NET_1_1
+ byte [] expected = { 0xA3, 0x0E, 0x34, 0x26, 0x8B, 0x49, 0xEF, 0x49 };
+#else
// Believe it or not, MACTripleDES returns different values in 1.1
byte[] expected = { 0xD6, 0x6D, 0x75, 0xD4, 0x75, 0xF1, 0x01, 0x71 };
-#else
- byte[] expected = { 0xA3, 0x0E, 0x34, 0x26, 0x8B, 0x49, 0xEF, 0x49 };
#endif
byte[] data = new byte [48];
Check ("3DESMAC-A4", key, data, expected);
// PKCS1MaskGenerationMethodTest.cs - NUnit Test Cases for PKCS1MaskGenerationMethod
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot (sebastien@ximian.com)
//
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
// This test will FAIL with MS framework 1.0 and 1.1 as their MGF1 implementation is buggy
// see ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1/pkcs-1v2-1-vec.zip for RSA tests vector
[Test]
+#if ! NET_2_0
[Ignore ("Known to fail under MS runtime - both 1.0 and 1.1")]
+#endif
public void PKCS1v21TestVector ()
{
pkcs1.HashName = "SHA1";
// PaddingModeTest.cs - NUnit Test Cases for PaddingMode
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot (sebastien@ximian.com)
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using NUnit.Framework;
using System;
-using System.IO;
using System.Security.Cryptography;
+using NUnit.Framework;
+
namespace MonoTests.System.Security.Cryptography {
[TestFixture]
- public class PaddingModeTest : Assertion {
+ public class PaddingModeTest {
private static byte[] key1 = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
private static byte[] key2 = { 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01 };
TripleDES tdes = GetTripleDES ();
byte[] data = GetData (8);
byte[] encdata = Encrypt (tdes, PaddingMode.None, data);
- AssertEquals ("TripleDESNone_ExactlyOneBlockSize_Encrypt", "23-61-AC-E6-C5-17-10-51", BitConverter.ToString (encdata));
+ Assert.AreEqual ("23-61-AC-E6-C5-17-10-51", BitConverter.ToString (encdata), "TripleDESNone_ExactlyOneBlockSize_Encrypt");
byte[] decdata = Decrypt (tdes, PaddingMode.None, encdata);
AssertEquals ("TripleDESNone_ExactlyOneBlockSize_Decrypt", data, decdata);
}
byte[] data = GetData (48);
byte[] encdata = Encrypt (tdes, PaddingMode.None, data);
// note: encrypted data is truncated to a multiple of block size
- AssertEquals ("TripleDESNone_ExactMultipleBlockSize_Encrypt", "23-61-AC-E6-C5-17-10-51-BF-AB-79-9C-CD-5E-79-40-16-81-0D-6B-40-E6-B2-E9-86-34-8A-9E-5D-56-DA-D1-0C-8C-76-0A-E1-69-A1-0A-B5-B5-7F-FC-5A-D0-6E-6A", BitConverter.ToString (encdata));
+ Assert.AreEqual ("23-61-AC-E6-C5-17-10-51-BF-AB-79-9C-CD-5E-79-40-16-81-0D-6B-40-E6-B2-E9-86-34-8A-9E-5D-56-DA-D1-0C-8C-76-0A-E1-69-A1-0A-B5-B5-7F-FC-5A-D0-6E-6A", BitConverter.ToString (encdata), "TripleDESNone_ExactMultipleBlockSize_Encrypt");
byte[] decdata = Decrypt (tdes, PaddingMode.None, encdata);
AssertEquals ("TripleDESNone_ExactMultipleBlockSize_Decrypt", GetData (48), decdata);
}
TripleDES tdes = GetTripleDES ();
byte[] data = GetData (7);
byte[] encdata = Encrypt (tdes, PaddingMode.PKCS7, data);
- AssertEquals ("TripleDESPKCS7_SmallerThanOneBlockSize_Encrypt", "C6-59-0E-E3-7F-26-92-B0", BitConverter.ToString (encdata));
+ Assert.AreEqual ("C6-59-0E-E3-7F-26-92-B0", BitConverter.ToString (encdata), "TripleDESPKCS7_SmallerThanOneBlockSize_Encrypt");
byte[] decdata = Decrypt (tdes, PaddingMode.PKCS7, encdata);
AssertEquals ("TripleDESPKCS7_SmallerThanOneBlockSize_Decrypt", data, decdata);
}
TripleDES tdes = GetTripleDES ();
byte[] data = GetData (8);
byte[] encdata = Encrypt (tdes, PaddingMode.PKCS7, data);
- AssertEquals ("TripleDESPKCS7_ExactlyOneBlockSize_Encrypt", "23-61-AC-E6-C5-17-10-51-C0-60-5B-6A-5C-B7-69-62", BitConverter.ToString (encdata));
+ Assert.AreEqual ("23-61-AC-E6-C5-17-10-51-C0-60-5B-6A-5C-B7-69-62", BitConverter.ToString (encdata), "TripleDESPKCS7_ExactlyOneBlockSize_Encrypt");
byte[] decdata = Decrypt (tdes, PaddingMode.PKCS7, encdata);
AssertEquals ("TripleDESPKCS7_ExactlyOneBlockSize_Decrypt", data, decdata);
}
TripleDES tdes = GetTripleDES ();
byte[] data = GetData (12);
byte[] encdata = Encrypt (tdes, PaddingMode.PKCS7, data);
- AssertEquals ("TripleDESPKCS7_MoreThanOneBlockSize_Encrypt", "23-61-AC-E6-C5-17-10-51-D9-CB-92-8C-76-89-35-84", BitConverter.ToString (encdata));
+ Assert.AreEqual ("23-61-AC-E6-C5-17-10-51-D9-CB-92-8C-76-89-35-84", BitConverter.ToString (encdata), "TripleDESPKCS7_MoreThanOneBlockSize_Encrypt");
byte[] decdata = Decrypt (tdes, PaddingMode.PKCS7, encdata);
AssertEquals ("TripleDESPKCS7_MoreThanOneBlockSize_Decrypt", data, decdata);
}
TripleDES tdes = GetTripleDES ();
byte[] data = GetData (48);
byte[] encdata = Encrypt (tdes, PaddingMode.PKCS7, data);
- AssertEquals ("TripleDESPKCS7_ExactMultipleBlockSize_Encrypt", "23-61-AC-E6-C5-17-10-51-BF-AB-79-9C-CD-5E-79-40-16-81-0D-6B-40-E6-B2-E9-86-34-8A-9E-5D-56-DA-D1-0C-8C-76-0A-E1-69-A1-0A-B5-B5-7F-FC-5A-D0-6E-6A-73-61-63-1C-58-A2-9C-B3", BitConverter.ToString (encdata));
+ Assert.AreEqual ("23-61-AC-E6-C5-17-10-51-BF-AB-79-9C-CD-5E-79-40-16-81-0D-6B-40-E6-B2-E9-86-34-8A-9E-5D-56-DA-D1-0C-8C-76-0A-E1-69-A1-0A-B5-B5-7F-FC-5A-D0-6E-6A-73-61-63-1C-58-A2-9C-B3", BitConverter.ToString (encdata), "TripleDESPKCS7_ExactMultipleBlockSize_Encrypt");
byte[] decdata = Decrypt (tdes, PaddingMode.PKCS7, encdata);
AssertEquals ("TripleDESPKCS7_ExactMultipleBlockSize_Decrypt", data, decdata);
}
TripleDES tdes = GetTripleDES ();
byte[] data = GetData (7);
byte[] encdata = Encrypt (tdes, PaddingMode.Zeros, data);
- AssertEquals ("TripleDESZeros_SmallerThanOneBlockSize_Encrypt", "B8-5C-5B-A5-06-0B-7E-C6", BitConverter.ToString (encdata));
+ Assert.AreEqual ("B8-5C-5B-A5-06-0B-7E-C6", BitConverter.ToString (encdata), "TripleDESZeros_SmallerThanOneBlockSize_Encrypt");
byte[] decdata = Decrypt (tdes, PaddingMode.Zeros, encdata);
- AssertEquals ("TripleDESZeros_SmallerThanOneBlockSize_Decrypt", "00-01-02-03-04-05-06-00", BitConverter.ToString (decdata));
+ Assert.AreEqual ("00-01-02-03-04-05-06-00", BitConverter.ToString (decdata), "TripleDESZeros_SmallerThanOneBlockSize_Decrypt");
}
[Test]
TripleDES tdes = GetTripleDES ();
byte[] data = GetData (8);
byte[] encdata = Encrypt (tdes, PaddingMode.Zeros, data);
- AssertEquals ("TripleDESZeros_ExactlyOneBlockSize_Encrypt", "23-61-AC-E6-C5-17-10-51", BitConverter.ToString (encdata));
+ Assert.AreEqual ("23-61-AC-E6-C5-17-10-51", BitConverter.ToString (encdata), "TripleDESZeros_ExactlyOneBlockSize_Encrypt");
byte[] decdata = Decrypt (tdes, PaddingMode.Zeros, encdata);
AssertEquals ("TripleDESZeros_ExactlyOneBlockSize_Decrypt", data, decdata);
}
TripleDES tdes = GetTripleDES ();
byte[] data = GetData (12);
byte[] encdata = Encrypt (tdes, PaddingMode.Zeros, data);
- AssertEquals ("TripleDESZeros_MoreThanOneBlockSize_Encrypt", "23-61-AC-E6-C5-17-10-51-6E-75-2E-33-12-09-5D-66", BitConverter.ToString (encdata));
+ Assert.AreEqual ("23-61-AC-E6-C5-17-10-51-6E-75-2E-33-12-09-5D-66", BitConverter.ToString (encdata), "TripleDESZeros_MoreThanOneBlockSize_Encrypt");
byte[] decdata = Decrypt (tdes, PaddingMode.Zeros, encdata);
- AssertEquals ("TripleDESZeros_MoreThanOneBlockSize_Decrypt", "00-01-02-03-04-05-06-07-08-09-0A-0B-00-00-00-00", BitConverter.ToString (decdata));
+ Assert.AreEqual ("00-01-02-03-04-05-06-07-08-09-0A-0B-00-00-00-00", BitConverter.ToString (decdata), "TripleDESZeros_MoreThanOneBlockSize_Decrypt");
}
[Test]
TripleDES tdes = GetTripleDES ();
byte[] data = GetData (48);
byte[] encdata = Encrypt (tdes, PaddingMode.Zeros, data);
- AssertEquals ("TripleDESZeros_ExactMultipleBlockSize_Encrypt", "23-61-AC-E6-C5-17-10-51-BF-AB-79-9C-CD-5E-79-40-16-81-0D-6B-40-E6-B2-E9-86-34-8A-9E-5D-56-DA-D1-0C-8C-76-0A-E1-69-A1-0A-B5-B5-7F-FC-5A-D0-6E-6A", BitConverter.ToString (encdata));
+ Assert.AreEqual ("23-61-AC-E6-C5-17-10-51-BF-AB-79-9C-CD-5E-79-40-16-81-0D-6B-40-E6-B2-E9-86-34-8A-9E-5D-56-DA-D1-0C-8C-76-0A-E1-69-A1-0A-B5-B5-7F-FC-5A-D0-6E-6A", BitConverter.ToString (encdata), "TripleDESZeros_ExactMultipleBlockSize_Encrypt");
byte[] decdata = Decrypt (tdes, PaddingMode.Zeros, encdata);
AssertEquals ("TripleDESZeros_ExactMultipleBlockSize_Decrypt", GetData (48), decdata);
}
Rijndael aes = GetAES ();
byte[] data = GetData (16);
byte[] encdata = Encrypt (aes, PaddingMode.None, data);
- AssertEquals ("RijndaelNone_ExactlyOneBlockSize_Encrypt", "79-42-36-2F-D6-DB-F1-0C-87-99-58-06-D5-F6-B0-BB", BitConverter.ToString (encdata));
+ Assert.AreEqual ("79-42-36-2F-D6-DB-F1-0C-87-99-58-06-D5-F6-B0-BB", BitConverter.ToString (encdata), "RijndaelNone_ExactlyOneBlockSize_Encrypt");
byte[] decdata = Decrypt (aes, PaddingMode.None, encdata);
AssertEquals ("RijndaelNone_ExactlyOneBlockSize_Decrypt", data, decdata);
}
byte[] data = GetData (48);
byte[] encdata = Encrypt (aes, PaddingMode.None, data);
// note: encrypted data is truncated to a multiple of block size
- AssertEquals ("RijndaelNone_ExactMultipleBlockSize_Encrypt", "79-42-36-2F-D6-DB-F1-0C-87-99-58-06-D5-F6-B0-BB-E1-27-3E-21-5A-BE-D5-12-F4-AF-06-8D-0A-BD-02-64-02-CB-FF-D7-32-19-5E-69-3C-54-C2-8C-A1-D7-72-FF", BitConverter.ToString (encdata));
+ Assert.AreEqual ("79-42-36-2F-D6-DB-F1-0C-87-99-58-06-D5-F6-B0-BB-E1-27-3E-21-5A-BE-D5-12-F4-AF-06-8D-0A-BD-02-64-02-CB-FF-D7-32-19-5E-69-3C-54-C2-8C-A1-D7-72-FF", BitConverter.ToString (encdata), "RijndaelNone_ExactMultipleBlockSize_Encrypt");
byte[] decdata = Decrypt (aes, PaddingMode.None, encdata);
AssertEquals ("RijndaelNone_ExactMultipleBlockSize_Decrypt", GetData (48), decdata);
}
Rijndael aes = GetAES ();
byte[] data = GetData (8);
byte[] encdata = Encrypt (aes, PaddingMode.PKCS7, data);
- AssertEquals ("RijndaelPKCS7_SmallerThanOneBlockSize_Encrypt", "AB-E0-20-5E-BC-28-A0-B7-A7-56-A3-BF-13-55-13-7E", BitConverter.ToString (encdata));
+ Assert.AreEqual ("AB-E0-20-5E-BC-28-A0-B7-A7-56-A3-BF-13-55-13-7E", BitConverter.ToString (encdata), "RijndaelPKCS7_SmallerThanOneBlockSize_Encrypt");
byte[] decdata = Decrypt (aes, PaddingMode.PKCS7, encdata);
AssertEquals ("RijndaelPKCS7_SmallerThanOneBlockSize_Decrypt", data, decdata);
}
Rijndael aes = GetAES ();
byte[] data = GetData (16);
byte[] encdata = Encrypt (aes, PaddingMode.PKCS7, data);
- AssertEquals ("RijndaelPKCS7_ExactlyOneBlockSize_Encrypt", "79-42-36-2F-D6-DB-F1-0C-87-99-58-06-D5-F6-B0-BB-60-CE-9F-E0-72-3B-D6-D1-A5-F8-33-D8-25-31-7F-D4", BitConverter.ToString (encdata));
+ Assert.AreEqual ("79-42-36-2F-D6-DB-F1-0C-87-99-58-06-D5-F6-B0-BB-60-CE-9F-E0-72-3B-D6-D1-A5-F8-33-D8-25-31-7F-D4", BitConverter.ToString (encdata), "RijndaelPKCS7_ExactlyOneBlockSize_Encrypt");
byte[] decdata = Decrypt (aes, PaddingMode.PKCS7, encdata);
AssertEquals ("RijndaelPKCS7_ExactlyOneBlockSize_Decrypt", data, decdata);
}
Rijndael aes = GetAES ();
byte[] data = GetData (20);
byte[] encdata = Encrypt (aes, PaddingMode.PKCS7, data);
- AssertEquals ("RijndaelPKCS7_MoreThanOneBlockSize_Encrypt", "79-42-36-2F-D6-DB-F1-0C-87-99-58-06-D5-F6-B0-BB-06-3F-D3-51-8D-55-E9-2F-02-4A-4E-F2-91-55-31-83", BitConverter.ToString (encdata));
+ Assert.AreEqual ("79-42-36-2F-D6-DB-F1-0C-87-99-58-06-D5-F6-B0-BB-06-3F-D3-51-8D-55-E9-2F-02-4A-4E-F2-91-55-31-83", BitConverter.ToString (encdata), "RijndaelPKCS7_MoreThanOneBlockSize_Encrypt");
byte[] decdata = Decrypt (aes, PaddingMode.PKCS7, encdata);
AssertEquals ("RijndaelPKCS7_MoreThanOneBlockSize_Decrypt", data, decdata);
}
Rijndael aes = GetAES ();
byte[] data = GetData (48);
byte[] encdata = Encrypt (aes, PaddingMode.PKCS7, data);
- AssertEquals ("RijndaelPKCS7_ExactMultipleBlockSize_Encrypt", "79-42-36-2F-D6-DB-F1-0C-87-99-58-06-D5-F6-B0-BB-E1-27-3E-21-5A-BE-D5-12-F4-AF-06-8D-0A-BD-02-64-02-CB-FF-D7-32-19-5E-69-3C-54-C2-8C-A1-D7-72-FF-37-42-81-21-47-A7-E0-AA-64-A7-8B-65-25-95-AA-54", BitConverter.ToString (encdata));
+ Assert.AreEqual ("79-42-36-2F-D6-DB-F1-0C-87-99-58-06-D5-F6-B0-BB-E1-27-3E-21-5A-BE-D5-12-F4-AF-06-8D-0A-BD-02-64-02-CB-FF-D7-32-19-5E-69-3C-54-C2-8C-A1-D7-72-FF-37-42-81-21-47-A7-E0-AA-64-A7-8B-65-25-95-AA-54", BitConverter.ToString (encdata), "RijndaelPKCS7_ExactMultipleBlockSize_Encrypt");
byte[] decdata = Decrypt (aes, PaddingMode.PKCS7, encdata);
AssertEquals ("RijndaelPKCS7_ExactMultipleBlockSize_Decrypt", data, decdata);
}
Rijndael aes = GetAES ();
byte[] data = GetData (8);
byte[] encdata = Encrypt (aes, PaddingMode.Zeros, data);
- AssertEquals ("RijndaelZeros_SmallerThanOneBlockSize_Encrypt", "DD-BE-D7-CE-E2-DD-5C-A3-3E-44-A1-76-00-E5-5B-5D", BitConverter.ToString (encdata));
+ Assert.AreEqual ("DD-BE-D7-CE-E2-DD-5C-A3-3E-44-A1-76-00-E5-5B-5D", BitConverter.ToString (encdata), "RijndaelZeros_SmallerThanOneBlockSize_Encrypt");
byte[] decdata = Decrypt (aes, PaddingMode.Zeros, encdata);
- AssertEquals ("RijndaelZeros_SmallerThanOneBlockSize_Decrypt", "00-01-02-03-04-05-06-07-00-00-00-00-00-00-00-00", BitConverter.ToString (decdata));
+ Assert.AreEqual ("00-01-02-03-04-05-06-07-00-00-00-00-00-00-00-00", BitConverter.ToString (decdata), "RijndaelZeros_SmallerThanOneBlockSize_Decrypt");
}
[Test]
Rijndael aes = GetAES ();
byte[] data = GetData (16);
byte[] encdata = Encrypt (aes, PaddingMode.Zeros, data);
- AssertEquals ("RijndaelZeros_ExactlyOneBlockSize_Encrypt", "79-42-36-2F-D6-DB-F1-0C-87-99-58-06-D5-F6-B0-BB", BitConverter.ToString (encdata));
+ Assert.AreEqual ("79-42-36-2F-D6-DB-F1-0C-87-99-58-06-D5-F6-B0-BB", BitConverter.ToString (encdata), "RijndaelZeros_ExactlyOneBlockSize_Encrypt");
byte[] decdata = Decrypt (aes, PaddingMode.Zeros, encdata);
AssertEquals ("RijndaelZeros_ExactlyOneBlockSize_Decrypt", data, decdata);
}
Rijndael aes = GetAES ();
byte[] data = GetData (20);
byte[] encdata = Encrypt (aes, PaddingMode.Zeros, data);
- AssertEquals ("RijndaelZeros_MoreThanOneBlockSize_Encrypt", "79-42-36-2F-D6-DB-F1-0C-87-99-58-06-D5-F6-B0-BB-04-6C-F7-A5-DE-FF-B4-30-29-7A-0E-04-3B-D4-B8-F2", BitConverter.ToString (encdata));
+ Assert.AreEqual ("79-42-36-2F-D6-DB-F1-0C-87-99-58-06-D5-F6-B0-BB-04-6C-F7-A5-DE-FF-B4-30-29-7A-0E-04-3B-D4-B8-F2", BitConverter.ToString (encdata), "RijndaelZeros_MoreThanOneBlockSize_Encrypt");
byte[] decdata = Decrypt (aes, PaddingMode.Zeros, encdata);
- AssertEquals ("RijndaelZeros_MoreThanOneBlockSize_Decrypt", "00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F-10-11-12-13-00-00-00-00-00-00-00-00-00-00-00-00", BitConverter.ToString (decdata));
+ Assert.AreEqual ("00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F-10-11-12-13-00-00-00-00-00-00-00-00-00-00-00-00", BitConverter.ToString (decdata), "RijndaelZeros_MoreThanOneBlockSize_Decrypt");
}
[Test]
Rijndael aes = GetAES ();
byte[] data = GetData (48);
byte[] encdata = Encrypt (aes, PaddingMode.Zeros, data);
- AssertEquals ("RijndaelZeros_ExactMultipleBlockSize_Encrypt", "79-42-36-2F-D6-DB-F1-0C-87-99-58-06-D5-F6-B0-BB-E1-27-3E-21-5A-BE-D5-12-F4-AF-06-8D-0A-BD-02-64-02-CB-FF-D7-32-19-5E-69-3C-54-C2-8C-A1-D7-72-FF", BitConverter.ToString (encdata));
+ Assert.AreEqual ("79-42-36-2F-D6-DB-F1-0C-87-99-58-06-D5-F6-B0-BB-E1-27-3E-21-5A-BE-D5-12-F4-AF-06-8D-0A-BD-02-64-02-CB-FF-D7-32-19-5E-69-3C-54-C2-8C-A1-D7-72-FF", BitConverter.ToString (encdata), "RijndaelZeros_ExactMultipleBlockSize_Encrypt");
byte[] decdata = Decrypt (aes, PaddingMode.Zeros, encdata);
AssertEquals ("RijndaelZeros_ExactMultipleBlockSize_Decrypt", GetData (48), decdata);
}
+
+ // Enum tests
+
+ [Test]
+ public void PaddingModeEnum ()
+ {
+#if NET_2_0
+ Assert.AreEqual (4, (int)PaddingMode.ANSIX923, "ANSIX923");
+ Assert.AreEqual (5, (int)PaddingMode.ISO10126, "ISO10126");
+#endif
+ Assert.AreEqual (1, (int)PaddingMode.None, "None");
+ Assert.AreEqual (2, (int)PaddingMode.PKCS7, "PKCS7");
+ Assert.AreEqual (3, (int)PaddingMode.Zeros, "Zeros");
+ }
+
+ // SymmetricAlgorithm tests
+
+ private byte[] GetKey (SymmetricAlgorithm sa)
+ {
+ byte[] key = new byte [sa.KeySize >> 3];
+ // no weak key this way (DES, TripleDES)
+ for (byte i=0; i < key.Length; i++)
+ key [i] = i;
+ return key;
+ }
+
+ private byte[] GetIV (SymmetricAlgorithm sa)
+ {
+ return new byte [sa.BlockSize >> 3];
+ }
+
+ private ICryptoTransform GetEncryptor (SymmetricAlgorithm sa, PaddingMode mode)
+ {
+ sa.Mode = CipherMode.ECB; // basic (no) mode
+ sa.Padding = mode;
+ return sa.CreateEncryptor (GetKey (sa), GetIV (sa));
+ }
+
+ private ICryptoTransform GetDecryptor (SymmetricAlgorithm sa, PaddingMode mode)
+ {
+ sa.Mode = CipherMode.ECB; // basic (no) mode
+ sa.Padding = mode;
+ return sa.CreateDecryptor (GetKey (sa), GetIV (sa));
+ }
+
+ // the best way to verify padding is to:
+ // a. encrypt data larger than one block with a padding mode "X"
+ // b. decrypt the data with padding mode "None"
+ // c. compare the last (padding) bytes with the expected padding
+#if NET_2_0
+ private void ANSIX923_Full (SymmetricAlgorithm sa)
+ {
+ int bs = (sa.BlockSize >> 3);
+ // one full block
+ byte[] data = new byte [bs]; // in bytes
+ ICryptoTransform enc = GetEncryptor (sa, PaddingMode.ANSIX923);
+ byte[] encdata = enc.TransformFinalBlock (data, 0, data.Length);
+ // one block of padding is added
+ Assert.AreEqual (data.Length * 2, encdata.Length, "one more block added");
+
+ ICryptoTransform dec = GetDecryptor (sa, PaddingMode.None);
+ byte[] decdata = dec.TransformFinalBlock (encdata, 0, encdata.Length);
+ Assert.AreEqual (encdata.Length, decdata.Length, "no unpadding");
+
+ int pd = decdata.Length - data.Length;
+ // now validate padding - ANSI X.923 is all 0 except last byte (length)
+ for (int i=0; i < bs - 1; i++)
+ Assert.AreEqual (0x00, decdata [decdata.Length - pd + i], i.ToString ());
+ Assert.AreEqual (pd, decdata [decdata.Length - 1], "last byte");
+ }
+
+ private void ANSIX923_Partial (SymmetricAlgorithm sa)
+ {
+ int bs = (sa.BlockSize >> 3);
+ // one and an half block
+ byte[] data = new byte [bs + (bs >> 1)]; // in bytes
+ ICryptoTransform enc = GetEncryptor (sa, PaddingMode.ANSIX923);
+ byte[] encdata = enc.TransformFinalBlock (data, 0, data.Length);
+ // one block of padding is added
+ Assert.AreEqual (bs * 2, encdata.Length, "one more block added");
+
+ ICryptoTransform dec = GetDecryptor (sa, PaddingMode.None);
+ byte[] decdata = dec.TransformFinalBlock (encdata, 0, encdata.Length);
+ Assert.AreEqual (encdata.Length, decdata.Length, "no unpadding");
+
+ int pd = decdata.Length - data.Length;
+ // now validate padding - ANSI X.923 is all 0 except last byte (length)
+ for (int i = 0; i < pd - 1; i++)
+ Assert.AreEqual (0x00, decdata [decdata.Length - pd + i], i.ToString ());
+ Assert.AreEqual (pd, decdata [decdata.Length - 1], "last byte");
+ }
+
+ private void ISO10126_Full (SymmetricAlgorithm sa)
+ {
+ int bs = (sa.BlockSize >> 3);
+ // one full block
+ byte [] data = new byte [bs]; // in bytes
+ ICryptoTransform enc = GetEncryptor (sa, PaddingMode.ISO10126);
+ byte [] encdata = enc.TransformFinalBlock (data, 0, data.Length);
+ // one block of padding is added
+ Assert.AreEqual (data.Length * 2, encdata.Length, "one more block added");
+
+ ICryptoTransform dec = GetDecryptor (sa, PaddingMode.None);
+ byte [] decdata = dec.TransformFinalBlock (encdata, 0, encdata.Length);
+ Assert.AreEqual (encdata.Length, decdata.Length, "no unpadding");
+
+ int pd = decdata.Length - data.Length;
+ // now validate padding - ISO10126 is all random except last byte (length)
+ Assert.AreEqual (pd, decdata [decdata.Length - 1], "last byte");
+ }
+
+ private void ISO10126_Partial (SymmetricAlgorithm sa)
+ {
+ int bs = (sa.BlockSize >> 3);
+ // one and an half block
+ byte [] data = new byte [bs + (bs >> 1)]; // in bytes
+ ICryptoTransform enc = GetEncryptor (sa, PaddingMode.ISO10126);
+ byte [] encdata = enc.TransformFinalBlock (data, 0, data.Length);
+ // one block of padding is added
+ Assert.AreEqual (bs * 2, encdata.Length, "one more block added");
+
+ ICryptoTransform dec = GetDecryptor (sa, PaddingMode.None);
+ byte [] decdata = dec.TransformFinalBlock (encdata, 0, encdata.Length);
+ Assert.AreEqual (encdata.Length, decdata.Length, "no unpadding");
+
+ int pd = decdata.Length - data.Length;
+ // now validate padding - ISO10126 is all random except last byte (length)
+ Assert.AreEqual (pd, decdata [decdata.Length - 1], "last byte");
+ }
+#endif
+ private void PKCS7_Full (SymmetricAlgorithm sa)
+ {
+ int bs = (sa.BlockSize >> 3);
+ // one full block
+ byte[] data = new byte [bs]; // in bytes
+ ICryptoTransform enc = GetEncryptor (sa, PaddingMode.PKCS7);
+ byte[] encdata = enc.TransformFinalBlock (data, 0, data.Length);
+ // one block of padding is added
+ Assert.AreEqual (data.Length * 2, encdata.Length, "one more block added");
+
+ ICryptoTransform dec = GetDecryptor (sa, PaddingMode.None);
+ byte[] decdata = dec.TransformFinalBlock (encdata, 0, encdata.Length);
+ Assert.AreEqual (encdata.Length, decdata.Length, "no unpadding");
+
+ int pd = decdata.Length - data.Length;
+ // now validate padding - PKCS7 is all padding char
+ for (int i = 0; i < bs; i++)
+ Assert.AreEqual (pd, decdata [decdata.Length - pd + i], i.ToString ());
+ }
+
+ private void PKCS7_Partial (SymmetricAlgorithm sa)
+ {
+ int bs = (sa.BlockSize >> 3);
+ // one and an half block
+ byte[] data = new byte[bs + (bs >> 1)]; // in bytes
+ ICryptoTransform enc = GetEncryptor (sa, PaddingMode.PKCS7);
+ byte[] encdata = enc.TransformFinalBlock (data, 0, data.Length);
+ // one block of padding is added
+ Assert.AreEqual (bs * 2, encdata.Length, "one more block added");
+
+ ICryptoTransform dec = GetDecryptor (sa, PaddingMode.None);
+ byte[] decdata = dec.TransformFinalBlock (encdata, 0, encdata.Length);
+ Assert.AreEqual (encdata.Length, decdata.Length, "no unpadding");
+
+ int pd = decdata.Length - data.Length;
+ // now validate padding - PKCS7 is all padding char
+ for (int i = 0; i < pd; i++)
+ Assert.AreEqual (pd, decdata [decdata.Length - pd + i], i.ToString ());
+ }
+
+ private void Zeros_Full (SymmetricAlgorithm sa)
+ {
+ int bs = (sa.BlockSize >> 3);
+ // one full block
+ byte [] data = new byte [bs]; // in bytes
+ for (int i = 0; i < data.Length; i++)
+ data [i] = 0xFF;
+
+ ICryptoTransform enc = GetEncryptor (sa, PaddingMode.Zeros);
+ byte [] encdata = enc.TransformFinalBlock (data, 0, data.Length);
+ // NO extra block is used for zero padding
+ Assert.AreEqual (data.Length, encdata.Length, "no extra block added");
+
+ ICryptoTransform dec = GetDecryptor (sa, PaddingMode.None);
+ byte [] decdata = dec.TransformFinalBlock (encdata, 0, encdata.Length);
+ Assert.AreEqual (encdata.Length, decdata.Length, "no unpadding");
+
+ // now validate absence of padding
+ Assert.AreEqual (0xFF, decdata [decdata.Length - 1], "no padding");
+ }
+
+ private void Zeros_Partial (SymmetricAlgorithm sa)
+ {
+ int bs = (sa.BlockSize >> 3);
+ // one and an half block
+ byte [] data = new byte [bs + (bs >> 1)]; // in bytes
+ for (int i=0; i < data.Length; i++)
+ data [i] = 0xFF;
+
+ ICryptoTransform enc = GetEncryptor (sa, PaddingMode.Zeros);
+ byte [] encdata = enc.TransformFinalBlock (data, 0, data.Length);
+ // one block of padding is added
+ Assert.AreEqual (bs * 2, encdata.Length, "one more block added");
+
+ ICryptoTransform dec = GetDecryptor (sa, PaddingMode.None);
+ byte [] decdata = dec.TransformFinalBlock (encdata, 0, encdata.Length);
+ Assert.AreEqual (encdata.Length, decdata.Length, "no unpadding");
+
+ int pd = decdata.Length - data.Length;
+ // now validate padding - Zeros is all 0x00 char
+ for (int i = 0; i < pd; i++)
+ Assert.AreEqual (0x00, decdata [decdata.Length - pd + i], i.ToString ());
+ }
+#if NET_2_0
+ // ANSI X.923
+
+ [Test]
+ public void DES_ANSIX923_Full ()
+ {
+ ANSIX923_Full (DES.Create ());
+ }
+
+ [Test]
+ public void DES_ANSIX923_Partial ()
+ {
+ ANSIX923_Partial (DES.Create ());
+ }
+
+ [Test]
+ public void RC2_ANSIX923_Full ()
+ {
+ ANSIX923_Full (RC2.Create ());
+ }
+
+ [Test]
+ public void RC2_ANSIX923_Partial ()
+ {
+ ANSIX923_Partial (RC2.Create ());
+ }
+
+ [Test]
+ public void Rijndael_ANSIX923_Full ()
+ {
+ ANSIX923_Full (Rijndael.Create ());
+ }
+
+ [Test]
+ public void Rijndael_ANSIX923_Partial ()
+ {
+ ANSIX923_Partial (Rijndael.Create ());
+ }
+
+ [Test]
+ public void TripleDES_ANSIX923_Full ()
+ {
+ ANSIX923_Full (TripleDES.Create ());
+ }
+
+ [Test]
+ public void TripleDES_ANSIX923_Partial ()
+ {
+ ANSIX923_Partial (TripleDES.Create ());
+ }
+
+ // ISO 10126
+
+ [Test]
+ public void DES_ISO10126_Full ()
+ {
+ ISO10126_Full (DES.Create ());
+ }
+
+ [Test]
+ public void DES_ISO10126_Partial ()
+ {
+ ISO10126_Partial (DES.Create ());
+ }
+
+ [Test]
+ public void RC2_ISO10126_Full ()
+ {
+ ISO10126_Full (RC2.Create ());
+ }
+
+ [Test]
+ public void RC2_ISO10126_Partial ()
+ {
+ ISO10126_Partial (RC2.Create ());
+ }
+
+ [Test]
+ public void Rijndael_ISO10126_Full ()
+ {
+ ISO10126_Full (Rijndael.Create ());
+ }
+
+ [Test]
+ public void Rijndael_ISO10126_Partial ()
+ {
+ ISO10126_Partial (Rijndael.Create ());
+ }
+
+ [Test]
+ public void TripleDES_ISO10126_Full ()
+ {
+ ISO10126_Full (TripleDES.Create ());
+ }
+
+ [Test]
+ public void TripleDES_ISO10126_Partial ()
+ {
+ ISO10126_Partial (TripleDES.Create ());
+ }
+#endif
+ // PKCS #7
+
+ [Test]
+ public void DES_PKCS7_Full ()
+ {
+ PKCS7_Full (DES.Create ());
+ }
+
+ [Test]
+ public void DES_PKCS7_Partial ()
+ {
+ PKCS7_Partial (DES.Create ());
+ }
+
+ [Test]
+ public void RC2_PKCS7_Full ()
+ {
+ PKCS7_Full (RC2.Create ());
+ }
+
+ [Test]
+ public void RC2_PKCS7_Partial ()
+ {
+ PKCS7_Partial (RC2.Create ());
+ }
+
+ [Test]
+ public void Rijndael_PKCS7_Full ()
+ {
+ PKCS7_Full (Rijndael.Create ());
+ }
+
+ [Test]
+ public void Rijndael_PKCS7_Partial ()
+ {
+ PKCS7_Partial (Rijndael.Create ());
+ }
+
+ [Test]
+ public void TripleDES_PKCS7_Full ()
+ {
+ PKCS7_Full (TripleDES.Create ());
+ }
+
+ [Test]
+ public void TripleDES_PKCS7_Partial ()
+ {
+ PKCS7_Partial (TripleDES.Create ());
+ }
+
+ // Zeros
+
+ [Test]
+ public void DES_Zeros_Full ()
+ {
+ Zeros_Full (DES.Create ());
+ }
+
+ [Test]
+ public void DES_Zeros_Partial ()
+ {
+ Zeros_Partial (DES.Create ());
+ }
+
+ [Test]
+ public void RC2_Zeros_Full ()
+ {
+ Zeros_Full (RC2.Create ());
+ }
+
+ [Test]
+ public void RC2_Zeros_Partial ()
+ {
+ Zeros_Partial (RC2.Create ());
+ }
+
+ [Test]
+ public void Rijndael_Zeros_Full ()
+ {
+ Zeros_Full (Rijndael.Create ());
+ }
+
+ [Test]
+ public void Rijndael_Zeros_Partial ()
+ {
+ Zeros_Partial (Rijndael.Create ());
+ }
+
+ [Test]
+ public void TripleDES_Zeros_Full ()
+ {
+ Zeros_Full (TripleDES.Create ());
+ }
+
+ [Test]
+ public void TripleDES_Zeros_Partial ()
+ {
+ Zeros_Partial (TripleDES.Create ());
+ }
+
+ // Padding mismatches
+
+ // the best way to test bad padding is to:
+ // a. encrypt data larger than one block with a padding mode "X"
+ // b. decrypt the data with padding mode "Y" (different with Y)
+ // c. check if the "bad" padding was removed correctly
+ //
+ // returns (bitmask)
+ // 1 - length difference
+ // 2 - original data lost
+ // 4 - CryptographicException thrown while decryption
+ private int Mismatch (PaddingMode encrypt, PaddingMode decrypt)
+ {
+ SymmetricAlgorithm sa = SymmetricAlgorithm.Create ();
+ int bs = (sa.BlockSize >> 3);
+ // one full block
+ byte [] data = new byte [bs]; // in bytes
+ ICryptoTransform enc = GetEncryptor (sa, encrypt);
+ byte [] encdata = enc.TransformFinalBlock (data, 0, data.Length);
+
+ int result = 0;
+ try {
+ ICryptoTransform dec = GetDecryptor (sa, decrypt);
+ byte [] decdata = dec.TransformFinalBlock (encdata, 0, encdata.Length);
+
+ if (data.Length != decdata.Length)
+ result += 1;
+
+ for (int i=0; i < data.Length; i++) {
+ if (data [i] != decdata [i]) {
+ result += 2;
+ break;
+ }
+ }
+ }
+ catch (CryptographicException) {
+ result += 4;
+ }
+ return result;
+ }
+#if NET_2_0
+ [Test]
+ public void ANSIX923_ISO10126 ()
+ {
+ Assert.AreEqual (0, Mismatch (PaddingMode.ANSIX923, PaddingMode.ISO10126));
+ }
+
+ [Test]
+ public void ANSIX923_None ()
+ {
+ Assert.AreEqual (1, Mismatch (PaddingMode.ANSIX923, PaddingMode.None));
+ }
+
+ [Test]
+ public void ANSIX923_PKCS7 ()
+ {
+ Assert.AreEqual (0, Mismatch (PaddingMode.ANSIX923, PaddingMode.PKCS7));
+ }
+
+ [Test]
+ public void ANSIX923_Zeros ()
+ {
+ Assert.AreEqual (1, Mismatch (PaddingMode.ANSIX923, PaddingMode.Zeros));
+ }
+
+ [Test]
+ public void ISO10126_ANSIX923 ()
+ {
+ Assert.AreEqual (4, Mismatch (PaddingMode.ISO10126, PaddingMode.ANSIX923));
+ }
+
+ [Test]
+ public void ISO10126_None ()
+ {
+ Assert.AreEqual (1, Mismatch (PaddingMode.ISO10126, PaddingMode.None));
+ }
+
+ [Test]
+ public void ISO10126_PKCS7 ()
+ {
+ Assert.AreEqual (4, Mismatch (PaddingMode.ISO10126, PaddingMode.PKCS7));
+ }
+
+ [Test]
+ public void ISO10126_Zeros ()
+ {
+ Assert.AreEqual (1, Mismatch (PaddingMode.ISO10126, PaddingMode.Zeros));
+ }
+
+ [Test]
+ public void None_ANSIX923 ()
+ {
+ Assert.AreEqual (4, Mismatch (PaddingMode.None, PaddingMode.ANSIX923));
+ }
+
+ [Test]
+ public void None_ISO10126 ()
+ {
+ Assert.AreEqual (4, Mismatch (PaddingMode.None, PaddingMode.ISO10126));
+ }
+#endif
+ [Test]
+ public void None_PKCS7 ()
+ {
+#if NET_2_0
+ Assert.AreEqual (4, Mismatch (PaddingMode.None, PaddingMode.PKCS7));
+#else
+ Assert.AreEqual (0, Mismatch (PaddingMode.None, PaddingMode.PKCS7));
+#endif
+ }
+
+ [Test]
+ public void None_Zeros ()
+ {
+ Assert.AreEqual (0, Mismatch (PaddingMode.None, PaddingMode.Zeros));
+ }
+#if NET_2_0
+ [Test]
+ public void PKCS7_ANSIX923 ()
+ {
+ Assert.AreEqual (4, Mismatch (PaddingMode.PKCS7, PaddingMode.ANSIX923));
+ }
+
+ [Test]
+ public void PKCS7_ISO10126 ()
+ {
+ Assert.AreEqual (0, Mismatch (PaddingMode.PKCS7, PaddingMode.ISO10126));
+ }
+#endif
+ [Test]
+ public void PKCS7_None ()
+ {
+ Assert.AreEqual (1, Mismatch (PaddingMode.PKCS7, PaddingMode.None));
+ }
+
+ [Test]
+ public void PKCS7_Zeros ()
+ {
+ Assert.AreEqual (1, Mismatch (PaddingMode.PKCS7, PaddingMode.Zeros));
+ }
+#if NET_2_0
+ [Test]
+ public void Zeros_ANSIX923 ()
+ {
+ Assert.AreEqual (4, Mismatch (PaddingMode.Zeros, PaddingMode.ANSIX923));
+ }
+
+ [Test]
+ public void Zeros_ISO10126 ()
+ {
+ Assert.AreEqual (4, Mismatch (PaddingMode.Zeros, PaddingMode.ISO10126));
+ }
+#endif
+ [Test]
+ public void Zeros_None ()
+ {
+ Assert.AreEqual (0, Mismatch (PaddingMode.Zeros, PaddingMode.None));
+ }
+
+ [Test]
+ public void Zeros_PKCS7 ()
+ {
+#if NET_2_0
+ Assert.AreEqual (4, Mismatch (PaddingMode.Zeros, PaddingMode.PKCS7));
+#else
+ Assert.AreEqual (0, Mismatch (PaddingMode.Zeros, PaddingMode.PKCS7));
+#endif
+ }
+
+ // MACTripleDES tests
+#if NET_2_0
+ private string MAC (PaddingMode padding, int length)
+ {
+ byte[] key = new byte [24] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
+ MACTripleDES mac = new MACTripleDES (key);
+ mac.Padding = padding;
+ byte[] data = new byte [length];
+ byte[] hash = mac.TransformFinalBlock (data, 0, data.Length);
+ string result = BitConverter.ToString (mac.Hash);
+ return result;
+ }
+
+ // Note: TripleDES block size is 8 bytes
+
+ [Test]
+ public void MACTripleDES_ANSIX923 ()
+ {
+ Assert.AreEqual ("F6-61-3E-C8-E4-A4-D1-A8", MAC (PaddingMode.ANSIX923, 8), "Full");
+ Assert.AreEqual ("62-C3-78-B0-27-FC-EB-E0", MAC (PaddingMode.ANSIX923, 4), "Partial");
+ }
+
+ [Test]
+ public void MACTripleDES_ISO10126 ()
+ {
+ // ISO 10126 use random in it's padding so we can't use it to get "repeatable" results
+ // (i.e. each call will get different result). This isn't a padding to use for MACing!!!
+ Assert.AreEqual (23, MAC (PaddingMode.ISO10126, 8).Length, "Full");
+ Assert.AreEqual (23, MAC (PaddingMode.ISO10126, 4).Length, "Partial");
+ }
+
+ [Test]
+ public void MACTripleDES_None ()
+ {
+ Assert.AreEqual ("46-34-5C-8E-EB-DC-74-5C", MAC (PaddingMode.None, 8), "Full");
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void MACTripleDES_None_Partial ()
+ {
+ // Illegal - must be a multiple of block size
+ MAC (PaddingMode.None, 4);
+ }
+
+ [Test]
+ public void MACTripleDES_PKCS7 ()
+ {
+ Assert.AreEqual ("17-71-9F-D5-0B-EF-1D-07", MAC (PaddingMode.PKCS7, 8), "Full");
+ Assert.AreEqual ("5B-3A-13-6F-3F-6F-13-22", MAC (PaddingMode.PKCS7, 4), "Partial");
+ }
+
+ [Test]
+ public void MACTripleDES_Zeros ()
+ {
+ Assert.AreEqual ("46-34-5C-8E-EB-DC-74-5C", MAC (PaddingMode.Zeros, 8));
+ Assert.AreEqual ("46-34-5C-8E-EB-DC-74-5C", MAC (PaddingMode.Zeros, 4));
+ }
+#endif
}
-}
\ No newline at end of file
+}
// Sebastien Pouliot (sebastien@ximian.com)
//
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://novell.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
// FIXME: should we treat this as a bug or as a feature ?
[Test]
+#if ! NET_2_0
[ExpectedException (typeof (NullReferenceException))]
+#endif
public void StrangeBehaviour ()
{
byte[] salt = { 0xDE, 0xAD, 0xC0, 0xDE };
-//\r
-// TestSuite.System.Security.Cryptography.RC2Test.cs\r
-//\r
-// Authors:\r
-// Andrew Birkett (andy@nobugs.org)\r
+//
+// TestSuite.System.Security.Cryptography.RC2Test.cs
+//
+// Authors:
+// Andrew Birkett (andy@nobugs.org)
// Sebastien Pouliot (sebastien@ximian.com)
//
-// (C) 2004 Novell (http://www.novell.com)
-//\r
-\r
-using System;\r
-using System.Security.Cryptography;\r
-\r
-using NUnit.Framework;\r
-\r
-namespace MonoTests.System.Security.Cryptography {\r
-
- [TestFixture]\r
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Security.Cryptography;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Security.Cryptography {
+
+ [TestFixture]
public class RC2Test : Assertion {
[Test]
public void DefaultLength ()
{
- RC2 algo = RC2.Create ();\r
+ RC2 algo = RC2.Create ();
AssertEquals ("Key Size", 128, algo.KeySize);
AssertEquals ("Key Length", 16, algo.Key.Length);
AssertEquals ("IV Length", 8, algo.IV.Length);
}
- private void CheckECB (int effective_bits, byte[] key, byte[] pt, byte[] expected)\r
- {\r
- RC2 c = RC2.Create ();\r
- c.Mode = CipherMode.ECB;\r
- c.Padding = PaddingMode.Zeros;\r
+ private void CheckECB (int effective_bits, byte[] key, byte[] pt, byte[] expected)
+ {
+ RC2 c = RC2.Create ();
+ c.Mode = CipherMode.ECB;
+ c.Padding = PaddingMode.Zeros;
c.Key = key;
- AssertEquals ("KeySize", key.Length * 8, c.KeySize);\r
- c.EffectiveKeySize = effective_bits;\r
-\r
- ICryptoTransform encryptor = c.CreateEncryptor ();\r
- ICryptoTransform decryptor = c.CreateDecryptor ();\r
-\r
- byte[] ct = new byte [pt.Length];\r
- int n = encryptor.TransformBlock (pt, 0, pt.Length, ct, 0);\r
- AssertEquals ("EncryptLen", n, pt.Length);\r
- for (int i=0; i < n; i++) {\r
- AssertEquals ("Encrypt" + i, ct [i], expected [i]);\r
- }\r
-\r
- byte[] rt = new byte [ct.Length];\r
- n = decryptor.TransformBlock (ct, 0, ct.Length, rt, 0);\r
- AssertEquals ("DecryptLen", n, ct.Length);\r
- for (int i=0; i < n; i++) {\r
- AssertEquals ("Decrypt" + i, rt [i], pt [i]);\r
- }\r
+ AssertEquals ("KeySize", key.Length * 8, c.KeySize);
+ c.EffectiveKeySize = effective_bits;
+
+ ICryptoTransform encryptor = c.CreateEncryptor ();
+ ICryptoTransform decryptor = c.CreateDecryptor ();
+
+ byte[] ct = new byte [pt.Length];
+ int n = encryptor.TransformBlock (pt, 0, pt.Length, ct, 0);
+ AssertEquals ("EncryptLen", n, pt.Length);
+ for (int i=0; i < n; i++) {
+ AssertEquals ("Encrypt" + i, ct [i], expected [i]);
+ }
+
+ byte[] rt = new byte [ct.Length];
+ n = decryptor.TransformBlock (ct, 0, ct.Length, rt, 0);
+ AssertEquals ("DecryptLen", n, ct.Length);
+ for (int i=0; i < n; i++) {
+ AssertEquals ("Decrypt" + i, rt [i], pt [i]);
+ }
}
[Test]
- [ExpectedException (typeof (CryptographicException))]\r
- public void RFC2268Vector_1 ()\r
- {\r
- byte[] key = { 0, 0, 0, 0, 0, 0, 0, 0 };\r
- byte[] pt = { 0, 0, 0, 0, 0, 0, 0, 0 };\r
- byte[] ct = { 0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff };\r
+#if NET_1_1
+ [ExpectedException (typeof (CryptographicUnexpectedOperationException))]
+#else
+ [ExpectedException (typeof (CryptographicException))]
+#endif
+ public void RFC2268Vector_1 ()
+ {
+ byte[] key = { 0, 0, 0, 0, 0, 0, 0, 0 };
+ byte[] pt = { 0, 0, 0, 0, 0, 0, 0, 0 };
+ byte[] ct = { 0xeb, 0xb7, 0x73, 0xf9, 0x93, 0x27, 0x8e, 0xff };
// we don't support EffectiveKeySize != KeySize to match MS implementation
- CheckECB (63, key, pt, ct);\r
- }\r
-
- [Test]\r
- public void RFC2268Vector_2 ()\r
- {\r
- byte[] key = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };\r
- byte[] pt = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };\r
- byte[] ct = { 0x27, 0x8b, 0x27, 0xe4, 0x2e, 0x2f, 0x0d, 0x49 };\r
-
- CheckECB (64, key, pt, ct);\r
- }\r
- \r
- [Test]\r
- public void RFC2268Vector_3 ()\r
- {\r
- byte[] key = { 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };\r
- byte[] pt = { 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };\r
- byte[] ct = { 0x30, 0x64, 0x9e, 0xdf, 0x9b, 0xe7, 0xd2, 0xc2 };\r
-
- CheckECB (64, key, pt, ct);\r
- }\r
-
- [Test]\r
- [ExpectedException (typeof (CryptographicException))]\r
+ CheckECB (63, key, pt, ct);
+ }
+
+ [Test]
+ public void RFC2268Vector_2 ()
+ {
+ byte[] key = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+ byte[] pt = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+ byte[] ct = { 0x27, 0x8b, 0x27, 0xe4, 0x2e, 0x2f, 0x0d, 0x49 };
+
+ CheckECB (64, key, pt, ct);
+ }
+
+ [Test]
+ public void RFC2268Vector_3 ()
+ {
+ byte[] key = { 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ byte[] pt = { 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
+ byte[] ct = { 0x30, 0x64, 0x9e, 0xdf, 0x9b, 0xe7, 0xd2, 0xc2 };
+
+ CheckECB (64, key, pt, ct);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
public void RFC2268Vector_4 ()
- {\r
- byte[] key = { 0x88 };\r
- byte[] pt = { 0, 0, 0, 0, 0, 0, 0, 0 };\r
- byte[] ct = { 0x61, 0xa8, 0xa2, 0x44, 0xad, 0xac, 0xcc, 0xf0 };\r
+ {
+ byte[] key = { 0x88 };
+ byte[] pt = { 0, 0, 0, 0, 0, 0, 0, 0 };
+ byte[] ct = { 0x61, 0xa8, 0xa2, 0x44, 0xad, 0xac, 0xcc, 0xf0 };
// we don't support KeySize < 40 to match MS implementation
- CheckECB (64, key, pt, ct);\r
- }\r
-\r
- [Test]\r
- [ExpectedException (typeof (CryptographicException))]\r
+ CheckECB (64, key, pt, ct);
+ }
+
+ [Test]
+#if NET_1_1
+ [ExpectedException (typeof (CryptographicUnexpectedOperationException))]
+#else
+ [ExpectedException (typeof (CryptographicException))]
+#endif
public void RFC2268Vector_5 ()
- {\r
- byte[] key = { 0x88, 0xbc, 0xa9, 0x0e, 0x90, 0x87, 0x5a };\r
- byte[] pt = { 0, 0, 0, 0, 0, 0, 0, 0 };\r
- byte[] ct = { 0x6c, 0xcf, 0x43, 0x08, 0x97, 0x4c, 0x26, 0x7f };\r
+ {
+ byte[] key = { 0x88, 0xbc, 0xa9, 0x0e, 0x90, 0x87, 0x5a };
+ byte[] pt = { 0, 0, 0, 0, 0, 0, 0, 0 };
+ byte[] ct = { 0x6c, 0xcf, 0x43, 0x08, 0x97, 0x4c, 0x26, 0x7f };
// we don't support EffectiveKeySize != KeySize to match MS implementation
- CheckECB (64, key, pt, ct);\r
- }\r
+ CheckECB (64, key, pt, ct);
+ }
- [Test]\r
- [ExpectedException (typeof (CryptographicException))]\r
+ [Test]
+#if NET_1_1
+ [ExpectedException (typeof (CryptographicUnexpectedOperationException))]
+#else
+ [ExpectedException (typeof (CryptographicException))]
+#endif
public void RFC2268Vector_6 ()
- {\r
- byte[] key = { 0x88, 0xbc, 0xa9, 0x0e, 0x90, 0x87, 0x5a, 0x7f, \r
- 0x0f, 0x79, 0xc3, 0x84, 0x62, 0x7b, 0xaf, 0xb2 };\r
- byte[] pt = { 0, 0, 0, 0, 0, 0, 0, 0 };\r
- byte[] ct = { 0x1a, 0x80, 0x7d, 0x27, 0x2b, 0xbe, 0x5d, 0xb1 };\r
+ {
+ byte[] key = { 0x88, 0xbc, 0xa9, 0x0e, 0x90, 0x87, 0x5a, 0x7f,
+ 0x0f, 0x79, 0xc3, 0x84, 0x62, 0x7b, 0xaf, 0xb2 };
+ byte[] pt = { 0, 0, 0, 0, 0, 0, 0, 0 };
+ byte[] ct = { 0x1a, 0x80, 0x7d, 0x27, 0x2b, 0xbe, 0x5d, 0xb1 };
// we don't support EffectiveKeySize != KeySize to match MS implementation
- CheckECB (64, key, pt, ct);\r
- }\r
+ CheckECB (64, key, pt, ct);
+ }
- [Test]\r
+ [Test]
public void RFC2268Vector_7 ()
- {\r
- byte[] key = { 0x88, 0xbc, 0xa9, 0x0e, 0x90, 0x87, 0x5a, 0x7f, \r
- 0x0f, 0x79, 0xc3, 0x84, 0x62, 0x7b, 0xaf, 0xb2 };\r
- byte[] pt = { 0, 0, 0, 0, 0, 0, 0, 0 };\r
- byte[] ct = { 0x22, 0x69, 0x55, 0x2a, 0xb0, 0xf8, 0x5c, 0xa6 };\r
-
- CheckECB (128, key, pt, ct);\r
- }\r
-\r
- [Test]\r
- [ExpectedException (typeof (CryptographicException))]\r
+ {
+ byte[] key = { 0x88, 0xbc, 0xa9, 0x0e, 0x90, 0x87, 0x5a, 0x7f,
+ 0x0f, 0x79, 0xc3, 0x84, 0x62, 0x7b, 0xaf, 0xb2 };
+ byte[] pt = { 0, 0, 0, 0, 0, 0, 0, 0 };
+ byte[] ct = { 0x22, 0x69, 0x55, 0x2a, 0xb0, 0xf8, 0x5c, 0xa6 };
+
+ CheckECB (128, key, pt, ct);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
public void RFC2268Vector_8 ()
- {\r
- byte[] key = { 0x88, 0xbc, 0xa9, 0x0e, 0x90, 0x87, 0x5a, 0x7f, \r
- 0x0f, 0x79, 0xc3, 0x84, 0x62, 0x7b, 0xaf, 0xb2, \r
- 0x16, 0xf8, 0x0a, 0x6f, 0x85, 0x92, 0x05, 0x84,\r
- 0xc4, 0x2f, 0xce, 0xb0, 0xbe, 0x25, 0x5d, 0xaf, 0x1e };\r
- byte[] pt = { 0, 0, 0, 0, 0, 0, 0, 0 };\r
+ {
+ byte[] key = { 0x88, 0xbc, 0xa9, 0x0e, 0x90, 0x87, 0x5a, 0x7f,
+ 0x0f, 0x79, 0xc3, 0x84, 0x62, 0x7b, 0xaf, 0xb2,
+ 0x16, 0xf8, 0x0a, 0x6f, 0x85, 0x92, 0x05, 0x84,
+ 0xc4, 0x2f, 0xce, 0xb0, 0xbe, 0x25, 0x5d, 0xaf, 0x1e };
+ byte[] pt = { 0, 0, 0, 0, 0, 0, 0, 0 };
byte[] ct = { 0x5b, 0x78, 0xd3, 0xa4, 0x3d, 0xff, 0xf1, 0xf1 };
-\r
+
// we don't support KeySize > 128 to match MS implementation
- CheckECB (129, key, pt, ct);\r
- }\r
- }\r
-}\r
+ CheckECB (129, key, pt, ct);
+ }
+ }
+}
// http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot (sebastien@ximian.com)
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
// http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot (sebastien@ximian.com)
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
if ((array1 == null) && (array2 == null))
return;
if (array1 == null)
- TestCase.Fail (msg + " -> First array is NULL");
+ Assert.Fail (msg + " -> First array is NULL");
if (array2 == null)
- TestCase.Fail (msg + " -> Second array is NULL");
-
+ Assert.Fail (msg + " -> Second array is NULL");
+
bool a = (array1.Length == array2.Length);
if (a) {
for (int i = 0; i < array1.Length; i++) {
msg += " -> Expected " + BitConverter.ToString (array1, 0);
msg += " is different than " + BitConverter.ToString (array2, 0);
}
- TestCase.Assert (msg, a);
+ Assert.IsTrue (a, msg);
}
// RIPEMD160 ("") = 9c1185a5c5e9fc54612808977ee8f548b2258d31
public void RIPEMD160_d (string testName, RIPEMD160 hash, byte[] input, byte[] result)
{
- byte[] output = hash.TransformFinalBlock (input, 0, input.Length);
- AssertEquals (testName + ".d.1", input, output);
- AssertEquals (testName + ".d.2", result, hash.Hash);
+ hash.TransformFinalBlock (input, 0, input.Length);
+ AssertEquals (testName + ".d", result, hash.Hash);
// required or next operation will still return old hash
hash.Initialize ();
}
byte[] copy = new byte [input.Length];
for (int i=0; i < input.Length - 1; i++)
hash.TransformBlock (input, i, 1, copy, i);
- byte[] output = hash.TransformFinalBlock (input, input.Length - 1, 1);
- TestCase.AssertEquals (testName + ".e.1", input [input.Length - 1], output [0]);
- AssertEquals (testName + ".e.2", result, hash.Hash);
+ hash.TransformFinalBlock (input, input.Length - 1, 1);
+ AssertEquals (testName + ".e", result, hash.Hash);
// required or next operation will still return old hash
hash.Initialize ();
}
// none of those values changes for any implementation of RIPEMD160
+ [Test]
public virtual void StaticInfo ()
{
string className = hash.ToString ();
- TestCase.AssertEquals (className + ".HashSize", 160, hash.HashSize);
- TestCase.AssertEquals (className + ".InputBlockSize", 1, hash.InputBlockSize);
- TestCase.AssertEquals (className + ".OutputBlockSize", 1, hash.OutputBlockSize);
+ Assert.AreEqual (160, hash.HashSize, className + ".HashSize");
+ Assert.AreEqual (1, hash.InputBlockSize, className + ".InputBlockSize");
+ Assert.AreEqual (1, hash.OutputBlockSize, className + ".OutputBlockSize");
}
}
}
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://www.novell.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
static int minKeySize = 384;
+ private bool machineKeyStore;
+
+ [TestFixtureSetUp]
+ public void FixtureSetUp ()
+ {
+ sha1OID = CryptoConfig.MapNameToOID ("SHA1");
+ disposed = new RSACryptoServiceProvider (minKeySize);
+ disposed.FromXmlString ("<RSAKeyValue><Modulus>vtXAf62+o50prNCTiVGTMzdhm4sMjK0QVDkKQLFGu2fJQCULt9NZBab14PiWfG1t</Modulus><Exponent>AQAB</Exponent><P>5y2AHOzIhTChIFzLsgZQAGfy3U8OPwFh</P><Q>01NUVJJv+hhIsnbFiSi24FLRrfr/qYuN</Q><DP>HKLAOdUCyazKaK3V9Yleo448wTkntJpB</DP><DQ>AH5MTxo8arAN02TVlzliG+n1lVtlp2at</DQ><InverseQ>ZpgJwTxSYpT81sQCuVUvX0AYrvSziNIw</InverseQ><D>CStiJYBmsZvincAj5qw5w3M8yGmE/9ls4yv7wenozzC4kZshpI2MuON0d2Z8f4aB</D></RSAKeyValue>");
+ // FX 2.0 beta 1 bug - we must use the key before clearing it
+ // http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=1bc807eb-c4ca-4c2d-8499-9f0470b71a29
+ int ks = disposed.KeySize;
+ disposed.Clear ();
+ }
+
[SetUp]
- public void SetUp ()
+ public void Setup ()
{
- if (disposed == null) {
- sha1OID = CryptoConfig.MapNameToOID ("SHA1");
- disposed = new RSACryptoServiceProvider (minKeySize);
- disposed.FromXmlString ("<RSAKeyValue><Modulus>vtXAf62+o50prNCTiVGTMzdhm4sMjK0QVDkKQLFGu2fJQCULt9NZBab14PiWfG1t</Modulus><Exponent>AQAB</Exponent><P>5y2AHOzIhTChIFzLsgZQAGfy3U8OPwFh</P><Q>01NUVJJv+hhIsnbFiSi24FLRrfr/qYuN</Q><DP>HKLAOdUCyazKaK3V9Yleo448wTkntJpB</DP><DQ>AH5MTxo8arAN02TVlzliG+n1lVtlp2at</DQ><InverseQ>ZpgJwTxSYpT81sQCuVUvX0AYrvSziNIw</InverseQ><D>CStiJYBmsZvincAj5qw5w3M8yGmE/9ls4yv7wenozzC4kZshpI2MuON0d2Z8f4aB</D></RSAKeyValue>");
- disposed.Clear ();
- }
+ machineKeyStore = RSACryptoServiceProvider.UseMachineKeyStore;
+ }
+
+ [TearDown]
+ public void TearDown ()
+ {
+ RSACryptoServiceProvider.UseMachineKeyStore = machineKeyStore;
}
public void AssertEquals (string msg, byte[] array1, byte[] array2)
[Test]
// LAMESPEC/BUG: Disposed object can still be used (but original keypair seems lost)
-#if NET_1_0
- [ExpectedException (typeof (CryptographicException))] // in MS.NET v.1.0
-#else
+#if NET_1_1
[ExpectedException (typeof (ObjectDisposedException))] // in MS.NET v.1.1
+#else
+ [ExpectedException (typeof (CryptographicException))] // in MS.NET v.1.0
#endif
public void DecryptDisposed ()
{
}
[Test]
-#if NET_1_0
- [ExpectedException (typeof (NullReferenceException))]
-#else
+#if NET_1_1
[ExpectedException (typeof (ArgumentNullException))]
+#else
+ [ExpectedException (typeof (NullReferenceException))]
#endif
public void SignDataByteArrayNull ()
{
rsa.SignHash (null, "1.3.14.3.2.26"); // SHA-1
}
+#if NET_2_0
+ [Test]
+ public void SignHashNullOID ()
+ {
+ byte [] hash = new byte [20];
+ rsa = new RSACryptoServiceProvider (minKeySize);
+ byte[] signature = rsa.SignHash (hash, null);
+ Assert ("Null OID == SHA1", rsa.VerifyHash (hash, "1.3.14.3.2.26", signature));
+ Assert ("Null OID", rsa.VerifyHash (hash, null, signature));
+ }
+#else
[Test]
[ExpectedException (typeof (CryptographicException))]
public void SignHashNullOID ()
rsa = new RSACryptoServiceProvider (minKeySize);
rsa.SignHash (hash, null);
}
+#endif
[Test]
[ExpectedException (typeof (ObjectDisposedException))]
}
[Test]
-#if NET_1_0
- [ExpectedException (typeof (NullReferenceException))]
-#else
+#if NET_1_1
[ExpectedException (typeof (ArgumentNullException))]
+#else
+ [ExpectedException (typeof (NullReferenceException))]
#endif
public void VerifyDataNullData ()
{
rsa.VerifyHash (hash, "1.3.14.3.2.26", null);
}
+#if NET_2_0
+ [Test]
+ public void ImportDisposed ()
+ {
+ RSACryptoServiceProvider import = new RSACryptoServiceProvider (minKeySize);
+ import.Clear ();
+ import.ImportParameters (AllTests.GetRsaKey (false));
+ // no exception from Fx 2.0 +
+ }
+#else
[Test]
[ExpectedException (typeof (ObjectDisposedException))]
public void ImportDisposed ()
{
disposed.ImportParameters (AllTests.GetRsaKey (false));
}
+#endif
[Test]
[ExpectedException (typeof (ObjectDisposedException))]
// will fail on MS runtime before Windows XP
}
}
+
+#if NET_2_0
+ [Test]
+ public void CspKeyContainerInfo_NewKeypair ()
+ {
+ rsa = new RSACryptoServiceProvider (minKeySize);
+ CspKeyContainerInfo info = rsa.CspKeyContainerInfo;
+ Assert ("Accessible", !info.Accessible);
+ // info.Exportable throws a CryptographicException at this stage
+ Assert ("HardwareDevice", !info.HardwareDevice);
+ AssertNotNull ("KeyContainerName", info.KeyContainerName);
+ AssertEquals ("KeyNumber", KeyNumber.Exchange, info.KeyNumber);
+ Assert ("MachineKeyStore", !info.MachineKeyStore);
+ // info.Protected throws a CryptographicException at this stage
+ AssertNotNull ("ProviderName", info.ProviderName);
+ AssertEquals ("ProviderType", 1, info.ProviderType);
+ Assert ("RandomlyGenerated", info.RandomlyGenerated);
+ Assert ("Removable", !info.Removable);
+ // info.UniqueKeyContainerName throws a CryptographicException at this stage
+ }
+
+ [Test]
+ public void CspKeyContainerInfo_ImportedKeypair ()
+ {
+ rsa = new RSACryptoServiceProvider (minKeySize);
+ RSAParameters rsap = AllTests.GetRsaKey (true);
+ rsa.ImportParameters (rsap);
+ CspKeyContainerInfo info = rsa.CspKeyContainerInfo;
+ Assert ("Accessible", info.Accessible);
+ Assert ("Exportable", info.Exportable);
+ Assert ("HardwareDevice", !info.HardwareDevice);
+ AssertNotNull ("KeyContainerName", info.KeyContainerName);
+ AssertEquals ("KeyNumber", KeyNumber.Exchange, info.KeyNumber);
+ Assert ("MachineKeyStore", !info.MachineKeyStore);
+ Assert ("Protected", !info.Protected);
+ AssertNotNull ("ProviderName", info.ProviderName);
+ AssertEquals ("ProviderType", 1, info.ProviderType);
+ Assert ("RandomlyGenerated", info.RandomlyGenerated);
+ Assert ("Removable", !info.Removable);
+ AssertNotNull ("UniqueKeyContainerName", info.UniqueKeyContainerName);
+ }
+
+ [Test]
+ public void CspKeyContainerInfo_ImportedPublicKey ()
+ {
+ rsa = new RSACryptoServiceProvider (minKeySize);
+ RSAParameters rsap = AllTests.GetRsaKey (false);
+ rsa.ImportParameters (rsap);
+ CspKeyContainerInfo info = rsa.CspKeyContainerInfo;
+ Assert ("Accessible", !info.Accessible);
+ // info.Exportable throws a CryptographicException at this stage
+ Assert ("HardwareDevice", !info.HardwareDevice);
+ AssertNotNull ("KeyContainerName", info.KeyContainerName);
+ AssertEquals ("KeyNumber", KeyNumber.Exchange, info.KeyNumber);
+ Assert ("MachineKeyStore", !info.MachineKeyStore);
+ // info.Protected throws a CryptographicException at this stage
+ AssertNotNull ("ProviderName", info.ProviderName);
+ AssertEquals ("ProviderType", 1, info.ProviderType);
+ Assert ("RandomlyGenerated", info.RandomlyGenerated);
+ Assert ("Removable", !info.Removable);
+ // info.UniqueKeyContainerName throws a CryptographicException at this stage
+ }
+
+ [Test]
+ public void ExportCspBlob_Full ()
+ {
+ rsa = new RSACryptoServiceProvider (minKeySize);
+ RSAParameters rsap = AllTests.GetRsaKey (true);
+ rsa.ImportParameters (rsap);
+
+ byte[] keypair = rsa.ExportCspBlob (true);
+ AssertEquals ("07-02-00-00-00-A4-00-00-52-53-41-32-00-04-00-00-11-00-00-00-CB-BD-1D-09-FD-E5-F8-46-59-8F-2A-CA-98-72-53-E2-7F-68-C1-F6-41-9A-7A-52-1F-A5-61-7B-2D-B1-AA-E0-4E-39-98-45-45-B2-34-88-74-53-09-06-9D-64-6A-EE-84-25-3A-D9-B7-B4-E6-3E-72-37-C7-DF-A3-E0-B8-AF-7F-80-8B-5B-8A-9D-71-19-46-EC-E1-60-0D-52-ED-76-48-CD-6F-EB-CE-48-EA-61-AB-02-5C-03-AF-BA-DF-B8-1F-F5-54-74-F0-B6-D6-40-A4-43-10-D4-EE-07-8D-36-F7-71-A8-9D-2B-AC-38-23-9C-CE-82-06-09-2F-F8-BB-99-65-FB-58-2A-BA-41-75-39-1F-9D-45-76-21-25-5B-2D-0A-04-AA-E7-FA-28-7E-3B-1E-5D-6E-23-F0-4E-12-32-F6-84-3D-9E-1A-B8-93-A4-FD-F4-AE-44-9F-EB-99-01-60-B5-A1-10-0B-81-08-C9-B3-B9-B1-81-AE-CF-EE-03-15-46-AF-00-E7-41-A4-A5-16-04-4D-52-52-33-CE-CF-B5-04-32-B4-A3-0D-EA-92-2E-B4-66-16-B4-40-98-86-9D-8B-02-35-20-0F-5A-D0-B1-66-88-D0-42-6C-3F-35-D9-D1-AA-EA-33-12-34-F6-53-F4-27-F0-B1-7F-C9-81-C9-67-1F-3C-C9-AD-74-41-47-0A-91-FC-38-2B-20-2E-9A-2E-69-F7-C1-59-FF-14-74-B7-EA-75-09-49-D9-3E-B1-F2-51-B0-54-9B-AC-D0-A4-83-01-DC-DD-07-EB-5A-9A-D6-FC-23-40-E2-E4-37-03-BA-3E-A6-4C-49-54-3D-DA-36-98-5A-24-F9-39-FE-07-98-84-95-A4-99-1B-0D-22-7A-E4-8A-FD-31-E9-42-E3-8A-6F-8F-3F-80-F9-A7-46-31-4C-A9-56-05-5C-1C-99-7E-8A-3A-BD-AD-61-A9-4C-86-78-F8-B7-51-03-75-F0-0A-FF-90-02-1E-47-F7-39-80-79-25-FB-ED-66-36-EA-98-E6-56-96-0F-2E-9E-4E-2B-40-BF-67-A9-67-B1-83-58-4F-15-32-86-C9-9F-11-E2-39-CD-7F-07-93-50-88-53-34-F7-71-F2-80-B3-23-94-AE-DB-5B-26-8D-19-01-63-BB-DA-4F-6C-B0-C1-B3-1C-5B-C8-4B-3A-46-E4-3F-88-B8-B7-C2-28-94-AF-94-48-CC-CE-A1-E1-FB-DD-3E-A1-74-4F-ED-26-99-93-0A-D2-F5-BE-C3-8D-D3-2C-09-6C-C5-68-AF-6A-E5-44-94-52-A9-F1-76-1C-11-BC-CF-AC-50-59-AD-F3-7F-C9-DA-3E-C9-2E-B8-DC-7F-E3-39-A9-82-C0-A2-0D-87-D6-69-26-39-5C-5E-74-65-C4-6B-8D-99-C7-B3-10-94-B2-41-96-57-01-38-81-84-27-B4-68-06-1E-25-31-3F-F8-CD-C1-30-DB-88-B9-C4-89-F2-FA-41-53-FC-DA-A5", BitConverter.ToString (keypair));
+ }
+
+ [Test]
+ public void ExportCspBlob_PublicOnly ()
+ {
+ rsa = new RSACryptoServiceProvider (minKeySize);
+ RSAParameters rsap = AllTests.GetRsaKey (true);
+ rsa.ImportParameters (rsap);
+
+ byte[] pubkey = rsa.ExportCspBlob (false);
+ AssertEquals ("06-02-00-00-00-A4-00-00-52-53-41-31-00-04-00-00-11-00-00-00-CB-BD-1D-09-FD-E5-F8-46-59-8F-2A-CA-98-72-53-E2-7F-68-C1-F6-41-9A-7A-52-1F-A5-61-7B-2D-B1-AA-E0-4E-39-98-45-45-B2-34-88-74-53-09-06-9D-64-6A-EE-84-25-3A-D9-B7-B4-E6-3E-72-37-C7-DF-A3-E0-B8-AF-7F-80-8B-5B-8A-9D-71-19-46-EC-E1-60-0D-52-ED-76-48-CD-6F-EB-CE-48-EA-61-AB-02-5C-03-AF-BA-DF-B8-1F-F5-54-74-F0-B6-D6-40-A4-43-10-D4-EE-07-8D-36-F7-71-A8-9D-2B-AC-38-23-9C-CE-82-06-09-2F-F8-BB", BitConverter.ToString (pubkey));
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void ExportCspBlob_MissingPrivateKey ()
+ {
+ rsa = new RSACryptoServiceProvider (minKeySize);
+ RSAParameters rsap = AllTests.GetRsaKey (false);
+ rsa.ImportParameters (rsap);
+
+ rsa.ExportCspBlob (true);
+ }
+
+ [Test]
+ public void ExportCspBlob_MissingPrivateKey_PublicOnly ()
+ {
+ rsa = new RSACryptoServiceProvider (minKeySize);
+ RSAParameters rsap = AllTests.GetRsaKey (false);
+ rsa.ImportParameters (rsap);
+
+ byte[] pubkey = rsa.ExportCspBlob (false);
+ AssertEquals ("06-02-00-00-00-A4-00-00-52-53-41-31-00-04-00-00-11-00-00-00-CB-BD-1D-09-FD-E5-F8-46-59-8F-2A-CA-98-72-53-E2-7F-68-C1-F6-41-9A-7A-52-1F-A5-61-7B-2D-B1-AA-E0-4E-39-98-45-45-B2-34-88-74-53-09-06-9D-64-6A-EE-84-25-3A-D9-B7-B4-E6-3E-72-37-C7-DF-A3-E0-B8-AF-7F-80-8B-5B-8A-9D-71-19-46-EC-E1-60-0D-52-ED-76-48-CD-6F-EB-CE-48-EA-61-AB-02-5C-03-AF-BA-DF-B8-1F-F5-54-74-F0-B6-D6-40-A4-43-10-D4-EE-07-8D-36-F7-71-A8-9D-2B-AC-38-23-9C-CE-82-06-09-2F-F8-BB", BitConverter.ToString (pubkey));
+ }
+
+ [Test]
+ public void ImportCspBlob_Keypair ()
+ {
+ byte[] blob = new byte [596] { 0x07, 0x02, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x52, 0x53, 0x41, 0x32, 0x00, 0x04, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0xCB, 0xBD, 0x1D, 0x09, 0xFD, 0xE5, 0xF8, 0x46, 0x59, 0x8F, 0x2A, 0xCA, 0x98, 0x72, 0x53, 0xE2, 0x7F, 0x68, 0xC1, 0xF6, 0x41, 0x9A, 0x7A, 0x52, 0x1F, 0xA5, 0x61, 0x7B, 0x2D, 0xB1, 0xAA, 0xE0, 0x4E, 0x39, 0x98, 0x45, 0x45, 0xB2, 0x34, 0x88, 0x74, 0x53, 0x09, 0x06, 0x9D, 0x64, 0x6A, 0xEE, 0x84, 0x25, 0x3A, 0xD9, 0xB7, 0xB4, 0xE6, 0x3E, 0x72, 0x37, 0xC7, 0xDF, 0xA3, 0xE0, 0xB8, 0xAF, 0x7F, 0x80, 0x8B, 0x5B, 0x8A, 0x9D, 0x71, 0x19, 0x46, 0xEC, 0xE1, 0x60, 0x0D, 0x52, 0xED, 0x76, 0x48, 0xCD, 0x6F, 0xEB, 0xCE, 0x48, 0xEA, 0x61, 0xAB, 0x02, 0x5C, 0x03, 0xAF, 0xBA, 0xDF, 0xB8, 0x1F, 0xF5, 0x54, 0x74, 0xF0, 0xB6, 0xD6, 0x40, 0xA4, 0x43, 0x10, 0xD4, 0xEE, 0x07, 0x8D, 0x36, 0xF7, 0x71, 0xA8, 0x9D, 0x2B, 0xAC, 0x38, 0x23, 0x9C, 0xCE, 0x82, 0x06, 0x09, 0x2F, 0xF8, 0xBB, 0x99, 0x65, 0xFB, 0x58, 0x2A, 0xBA, 0x41, 0x75, 0x39, 0x1F, 0x9D, 0x45, 0x76, 0x21, 0x25, 0x5B, 0x2D, 0x0A, 0x04, 0xAA, 0xE7, 0xFA, 0x28, 0x7E, 0x3B, 0x1E, 0x5D, 0x6E, 0x23, 0xF0, 0x4E, 0x12, 0x32, 0xF6, 0x84, 0x3D, 0x9E, 0x1A, 0xB8, 0x93, 0xA4, 0xFD, 0xF4, 0xAE, 0x44, 0x9F, 0xEB, 0x99, 0x01, 0x60, 0xB5, 0xA1, 0x10, 0x0B, 0x81, 0x08, 0xC9, 0xB3, 0xB9, 0xB1, 0x81, 0xAE, 0xCF, 0xEE, 0x03, 0x15, 0x46, 0xAF, 0x00, 0xE7, 0x41, 0xA4, 0xA5, 0x16, 0x04, 0x4D, 0x52, 0x52, 0x33, 0xCE, 0xCF, 0xB5, 0x04, 0x32, 0xB4, 0xA3, 0x0D, 0xEA, 0x92, 0x2E, 0xB4, 0x66, 0x16, 0xB4, 0x40, 0x98, 0x86, 0x9D, 0x8B, 0x02, 0x35, 0x20, 0x0F, 0x5A, 0xD0, 0xB1, 0x66, 0x88, 0xD0, 0x42, 0x6C, 0x3F, 0x35, 0xD9, 0xD1, 0xAA, 0xEA, 0x33, 0x12, 0x34, 0xF6, 0x53, 0xF4, 0x27, 0xF0, 0xB1, 0x7F, 0xC9, 0x81, 0xC9, 0x67, 0x1F, 0x3C, 0xC9, 0xAD, 0x74, 0x41, 0x47, 0x0A, 0x91, 0xFC, 0x38, 0x2B, 0x20, 0x2E, 0x9A, 0x2E, 0x69, 0xF7, 0xC1, 0x59, 0xFF, 0x14, 0x74, 0xB7, 0xEA, 0x75, 0x09, 0x49, 0xD9, 0x3E, 0xB1, 0xF2, 0x51, 0xB0, 0x54, 0x9B, 0xAC, 0xD0, 0xA4, 0x83, 0x01, 0xDC, 0xDD, 0x07, 0xEB, 0x5A, 0x9A, 0xD6, 0xFC, 0x23, 0x40, 0xE2, 0xE4, 0x37, 0x03, 0xBA, 0x3E, 0xA6, 0x4C, 0x49, 0x54, 0x3D, 0xDA, 0x36, 0x98, 0x5A, 0x24, 0xF9, 0x39, 0xFE, 0x07, 0x98, 0x84, 0x95, 0xA4, 0x99, 0x1B, 0x0D, 0x22, 0x7A, 0xE4, 0x8A, 0xFD, 0x31, 0xE9, 0x42, 0xE3, 0x8A, 0x6F, 0x8F, 0x3F, 0x80, 0xF9, 0xA7, 0x46, 0x31, 0x4C, 0xA9, 0x56, 0x05, 0x5C, 0x1C, 0x99, 0x7E, 0x8A, 0x3A, 0xBD, 0xAD, 0x61, 0xA9, 0x4C, 0x86, 0x78, 0xF8, 0xB7, 0x51, 0x03, 0x75, 0xF0, 0x0A, 0xFF, 0x90, 0x02, 0x1E, 0x47, 0xF7, 0x39, 0x80, 0x79, 0x25, 0xFB, 0xED, 0x66, 0x36, 0xEA, 0x98, 0xE6, 0x56, 0x96, 0x0F, 0x2E, 0x9E, 0x4E, 0x2B, 0x40, 0xBF, 0x67, 0xA9, 0x67, 0xB1, 0x83, 0x58, 0x4F, 0x15, 0x32, 0x86, 0xC9, 0x9F, 0x11, 0xE2, 0x39, 0xCD, 0x7F, 0x07, 0x93, 0x50, 0x88, 0x53, 0x34, 0xF7, 0x71, 0xF2, 0x80, 0xB3, 0x23, 0x94, 0xAE, 0xDB, 0x5B, 0x26, 0x8D, 0x19, 0x01, 0x63, 0xBB, 0xDA, 0x4F, 0x6C, 0xB0, 0xC1, 0xB3, 0x1C, 0x5B, 0xC8, 0x4B, 0x3A, 0x46, 0xE4, 0x3F, 0x88, 0xB8, 0xB7, 0xC2, 0x28, 0x94, 0xAF, 0x94, 0x48, 0xCC, 0xCE, 0xA1, 0xE1, 0xFB, 0xDD, 0x3E, 0xA1, 0x74, 0x4F, 0xED, 0x26, 0x99, 0x93, 0x0A, 0xD2, 0xF5, 0xBE, 0xC3, 0x8D, 0xD3, 0x2C, 0x09, 0x6C, 0xC5, 0x68, 0xAF, 0x6A, 0xE5, 0x44, 0x94, 0x52, 0xA9, 0xF1, 0x76, 0x1C, 0x11, 0xBC, 0xCF, 0xAC, 0x50, 0x59, 0xAD, 0xF3, 0x7F, 0xC9, 0xDA, 0x3E, 0xC9, 0x2E, 0xB8, 0xDC, 0x7F, 0xE3, 0x39, 0xA9, 0x82, 0xC0, 0xA2, 0x0D, 0x87, 0xD6, 0x69, 0x26, 0x39, 0x5C, 0x5E, 0x74, 0x65, 0xC4, 0x6B, 0x8D, 0x99, 0xC7, 0xB3, 0x10, 0x94, 0xB2, 0x41, 0x96, 0x57, 0x01, 0x38, 0x81, 0x84, 0x27, 0xB4, 0x68, 0x06, 0x1E, 0x25, 0x31, 0x3F, 0xF8, 0xCD, 0xC1, 0x30, 0xDB, 0x88, 0xB9, 0xC4, 0x89, 0xF2, 0xFA, 0x41, 0x53, 0xFC, 0xDA, 0xA5 };
+ rsa = new RSACryptoServiceProvider (minKeySize);
+ rsa.ImportCspBlob (blob);
+
+ byte[] keypair = rsa.ExportCspBlob (true);
+ for (int i=0; i < blob.Length; i++)
+ AssertEquals (i.ToString (), blob [i], keypair [i]);
+ }
+
+ [Test]
+ public void ExportCspBlob_PublicKey ()
+ {
+ byte[] blob = new byte [148] { 0x06, 0x02, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x52, 0x53, 0x41, 0x31, 0x00, 0x04, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0xCB, 0xBD, 0x1D, 0x09, 0xFD, 0xE5, 0xF8, 0x46, 0x59, 0x8F, 0x2A, 0xCA, 0x98, 0x72, 0x53, 0xE2, 0x7F, 0x68, 0xC1, 0xF6, 0x41, 0x9A, 0x7A, 0x52, 0x1F, 0xA5, 0x61, 0x7B, 0x2D, 0xB1, 0xAA, 0xE0, 0x4E, 0x39, 0x98, 0x45, 0x45, 0xB2, 0x34, 0x88, 0x74, 0x53, 0x09, 0x06, 0x9D, 0x64, 0x6A, 0xEE, 0x84, 0x25, 0x3A, 0xD9, 0xB7, 0xB4, 0xE6, 0x3E, 0x72, 0x37, 0xC7, 0xDF, 0xA3, 0xE0, 0xB8, 0xAF, 0x7F, 0x80, 0x8B, 0x5B, 0x8A, 0x9D, 0x71, 0x19, 0x46, 0xEC, 0xE1, 0x60, 0x0D, 0x52, 0xED, 0x76, 0x48, 0xCD, 0x6F, 0xEB, 0xCE, 0x48, 0xEA, 0x61, 0xAB, 0x02, 0x5C, 0x03, 0xAF, 0xBA, 0xDF, 0xB8, 0x1F, 0xF5, 0x54, 0x74, 0xF0, 0xB6, 0xD6, 0x40, 0xA4, 0x43, 0x10, 0xD4, 0xEE, 0x07, 0x8D, 0x36, 0xF7, 0x71, 0xA8, 0x9D, 0x2B, 0xAC, 0x38, 0x23, 0x9C, 0xCE, 0x82, 0x06, 0x09, 0x2F, 0xF8, 0xBB };
+ rsa = new RSACryptoServiceProvider (minKeySize);
+ rsa.ImportCspBlob (blob);
+
+ byte[] pubkey = rsa.ExportCspBlob (false);
+ for (int i = 0; i < blob.Length; i++)
+ AssertEquals (i.ToString (), blob [i], pubkey [i]);
+ }
+
+ [Test]
+// [ExpectedException (typeof (ArgumentNullException))]
+// http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=2b7ff7d4-67db-43f0-8eba-20d962708140
+ [ExpectedException (typeof (NullReferenceException))]
+ public void ImportCspBlob_Null ()
+ {
+ rsa = new RSACryptoServiceProvider (minKeySize);
+ rsa.ImportCspBlob (null);
+ }
+
+ [Test]
+ [ExpectedException (typeof (CryptographicException))]
+ public void ImportCspBlob_Bad ()
+ {
+ byte[] blob = new byte [148]; // valid size for public key
+ rsa = new RSACryptoServiceProvider (minKeySize);
+ rsa.ImportCspBlob (blob);
+ }
+#endif
}
}
// Sebastien Pouliot (sebastien@ximian.com)
//
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://www.novell.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
}
[Test]
+#if NET_2_0
+ [ExpectedException (typeof (CryptographicUnexpectedOperationException))]
+#else
[ExpectedException (typeof (NullReferenceException))]
+#endif
public void ExchangeNoKey ()
{
AsymmetricKeyExchangeDeformatter keyex = new RSAOAEPKeyExchangeDeformatter ();
// Sebastien Pouliot (sebastien@ximian.com)
//
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://www.novell.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
}
[Test]
+#if NET_2_0
+ [ExpectedException (typeof (CryptographicUnexpectedOperationException))]
+#else
[ExpectedException (typeof (NullReferenceException))]
+#endif
public void ExchangeNoKey ()
{
AsymmetricKeyExchangeFormatter keyex = new RSAOAEPKeyExchangeFormatter ();
// Sebastien Pouliot (sebastien@ximian.com)
//
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://www.novell.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
}
[Test]
- [ExpectedException (typeof (NullReferenceException))]
+ [ExpectedException (typeof (ArgumentNullException))]
+#if ! NET_2_0
[Ignore ("Sometime causes System.ExecutionEngineException on MS implementation")]
+#endif
public void KeyExchangeNull ()
{
AsymmetricKeyExchangeFormatter keyex = new RSAPKCS1KeyExchangeFormatter (key);
}
[Test]
+#if NET_2_0
+ [ExpectedException (typeof (CryptographicUnexpectedOperationException))]
+#else
[ExpectedException (typeof (NullReferenceException))]
+#endif
public void ExchangeNoKey ()
{
AsymmetricKeyExchangeFormatter keyex = new RSAPKCS1KeyExchangeFormatter ();
fmt = new RSAPKCS1SignatureDeformatter ();
AssertNotNull ("RSAPKCS1SignatureDeformatter()", fmt);
- fmt = new RSAPKCS1SignatureDeformatter (null);
- AssertNotNull ("RSAPKCS1SignatureDeformatter(null)", fmt);
-
fmt = new RSAPKCS1SignatureDeformatter (rsa);
AssertNotNull ("RSAPKCS1SignatureDeformatter(rsa)", fmt);
}
+ [Test]
+#if NET_2_0
+ [ExpectedException (typeof (ArgumentNullException))]
+#endif
+ public void RSAConstructor_Null ()
+ {
+ RSAPKCS1SignatureDeformatter fmt = new RSAPKCS1SignatureDeformatter (null);
+ AssertNotNull ("RSAPKCS1SignatureDeformatter(null)", fmt);
+ }
+
[Test]
[ExpectedException (typeof (InvalidCastException))]
public void DSAConstructor ()
}
[Test]
- public void SetNullKey ()
+#if NET_2_0
+ [ExpectedException (typeof (ArgumentNullException))]
+#endif
+ public void SetNullKey ()
{
RSAPKCS1SignatureDeformatter fmt = new RSAPKCS1SignatureDeformatter ();
fmt.SetKey (null);
// Sebastien Pouliot (sebastien@ximian.com)
//
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://www.novell.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
}
[Test]
+#if NET_2_0
+ [ExpectedException (typeof (ArgumentNullException))]
+#endif
public void ConstructorNull ()
{
fmt = new RSAPKCS1SignatureFormatter (null);
}
[Test]
- public void SetKeyNull ()
+#if NET_2_0
+ [ExpectedException (typeof (ArgumentNullException))]
+#endif
+ public void SetKeyNull ()
{
fmt = new RSAPKCS1SignatureFormatter ();
fmt.SetKey (null);
// Rfc2898DeriveBytesTest.cs - NUnit Test Cases for Rfc2898DeriveBytes
//
// Author:
-// Sebastien Pouliot (spouliot@motus.com)
+// Sebastien Pouliot <spouliot@ximian.com>
//
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
[ExpectedException (typeof (ArgumentNullException))]
public void ConstructorPasswordNullSaltIterations ()
{
- Rfc2898DeriveBytes pkcs5 = new Rfc2898DeriveBytes (null, salt, 5);
+ string password = null;
+ Rfc2898DeriveBytes pkcs5 = new Rfc2898DeriveBytes (password, salt, 5);
}
[Test]
// Author:
// Sebastien Pouliot <spouliot@ximian.com>
//
-// (C) 2004 Novell (http://www.novell.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
}
[Test]
+#if NET_2_0
+ [ExpectedException (typeof (CryptographicException))]
+#endif
public void IV_None ()
{
SymmetricAlgorithm algo = SymmetricAlgorithm.Create ();
// Author:
// Sebastien Pouliot (sebastien@ximian.com)
//
-// (C) 2004 Novell (http://www.novell.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
}
[Test]
-// [ExpectedException (typeof (ArgumentNullException))]
+ [ExpectedException (typeof (ArgumentNullException))]
+#if ! NET_2_0
[Ignore ("MS throw a ExecutionEngineException")]
+#endif
public void TransformBlock_NullOutput ()
{
byte[] input = new byte [3];
}
[Test]
+#if NET_2_0
+ [ExpectedException (typeof (ArgumentOutOfRangeException))]
+#else
[ExpectedException (typeof (IndexOutOfRangeException))]
+#endif
public void TransformBlock_OutputOffset_Negative ()
{
byte[] input = new byte [15];
}
[Test]
+#if NET_2_0
+ [ExpectedException (typeof (ArgumentException))]
+#else
[ExpectedException (typeof (IndexOutOfRangeException))]
+#endif
public void TransformBlock_OutputOffset_Overflow ()
{
byte[] input = new byte [15];