// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2007,2011 Novell, Inc (http://www.novell.com)
+// Copyright 2011 Xamarin Inc (http://www.xamarin.com).
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
object o = CryptoConfig.CreateFromName (name);
if (objectname == null)
Assert.IsNull (o, name);
- else\r
+ else
Assert.AreEqual (objectname, o.ToString (), name);
}
CreateFromName ("System.Security.Cryptography.HMACSHA1", "System.Security.Cryptography.HMACSHA1");
CreateFromName ("MACTripleDES", "System.Security.Cryptography.MACTripleDES");
CreateFromName ("System.Security.Cryptography.MACTripleDES", "System.Security.Cryptography.MACTripleDES");
-#if NET_2_0\r
- // new HMAC - new base class doesn't return anything with it's short name\r
+#if NET_2_0
+ // new HMAC - new base class doesn't return anything with it's short name
Assert.IsNull (CryptoConfig.CreateFromName ("HMAC"), "HMAC");
- CreateFromName ("System.Security.Cryptography.HMAC", "System.Security.Cryptography.HMACSHA1");\r
- CreateFromName ("HMACMD5", "System.Security.Cryptography.HMACMD5");\r
- CreateFromName ("System.Security.Cryptography.HMACMD5", "System.Security.Cryptography.HMACMD5");\r
- CreateFromName ("HMACRIPEMD160", "System.Security.Cryptography.HMACRIPEMD160");\r
- CreateFromName ("System.Security.Cryptography.HMACRIPEMD160", "System.Security.Cryptography.HMACRIPEMD160");\r
- CreateFromName ("HMACSHA256", "System.Security.Cryptography.HMACSHA256");\r
- CreateFromName ("System.Security.Cryptography.HMACSHA256", "System.Security.Cryptography.HMACSHA256");\r
- CreateFromName ("HMACSHA384", "System.Security.Cryptography.HMACSHA384");\r
- CreateFromName ("System.Security.Cryptography.HMACSHA384", "System.Security.Cryptography.HMACSHA384");\r
- CreateFromName ("HMACSHA512", "System.Security.Cryptography.HMACSHA512");\r
- CreateFromName ("System.Security.Cryptography.HMACSHA512", "System.Security.Cryptography.HMACSHA512");\r
- // new hash algorithm\r
- CreateFromName ("RIPEMD160", "System.Security.Cryptography.RIPEMD160Managed");\r
- CreateFromName ("RIPEMD-160", "System.Security.Cryptography.RIPEMD160Managed");\r
+ CreateFromName ("System.Security.Cryptography.HMAC", "System.Security.Cryptography.HMACSHA1");
+ CreateFromName ("HMACMD5", "System.Security.Cryptography.HMACMD5");
+ CreateFromName ("System.Security.Cryptography.HMACMD5", "System.Security.Cryptography.HMACMD5");
+ CreateFromName ("HMACRIPEMD160", "System.Security.Cryptography.HMACRIPEMD160");
+ CreateFromName ("System.Security.Cryptography.HMACRIPEMD160", "System.Security.Cryptography.HMACRIPEMD160");
+ CreateFromName ("HMACSHA256", "System.Security.Cryptography.HMACSHA256");
+ CreateFromName ("System.Security.Cryptography.HMACSHA256", "System.Security.Cryptography.HMACSHA256");
+ CreateFromName ("HMACSHA384", "System.Security.Cryptography.HMACSHA384");
+ CreateFromName ("System.Security.Cryptography.HMACSHA384", "System.Security.Cryptography.HMACSHA384");
+ CreateFromName ("HMACSHA512", "System.Security.Cryptography.HMACSHA512");
+ CreateFromName ("System.Security.Cryptography.HMACSHA512", "System.Security.Cryptography.HMACSHA512");
+ // new hash algorithm
+ CreateFromName ("RIPEMD160", "System.Security.Cryptography.RIPEMD160Managed");
+ CreateFromName ("RIPEMD-160", "System.Security.Cryptography.RIPEMD160Managed");
CreateFromName ("System.Security.Cryptography.RIPEMD160", "System.Security.Cryptography.RIPEMD160Managed");
// x.509 stuff
- CreateFromName ("X509Chain", "System.Security.Cryptography.X509Certificates.X509Chain");\r
+#if !TARGET_JVM //TargetJvmNotWorking - this algorithm should be added to System
+ CreateFromName ("X509Chain", "System.Security.Cryptography.X509Certificates.X509Chain");
+#endif
#endif
// note: CryptoConfig can create any object !
CreateFromName ("System.Security.Cryptography.CryptoConfig", "System.Security.Cryptography.CryptoConfig");
CreateFromName ("System.IO.MemoryStream", "System.IO.MemoryStream");
- // non existing algo should return null (without exception)\r
+ // non existing algo should return null (without exception)
Assert.IsNull (CryptoConfig.CreateFromName ("NonExistingAlgorithm"), "NonExistingAlgorithm");
}
// additional names (URL) used for XMLDSIG (System.Security.Cryptography.Xml)
// URL taken from http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/
[Test]
+#if NET_2_1
+ [Ignore ("System.Security.dll is not part of Moonlight, MonoTouch and Mono for Android")]
+#endif
public void CreateFromURL ()
{
// URL used in SignatureMethod element
CreateFromName ("http://www.w3.org/2000/09/xmldsig#hmac-sha1", null);
// URL used in DigestMethod element
CreateFromName ("http://www.w3.org/2000/09/xmldsig#sha1", "System.Security.Cryptography.SHA1CryptoServiceProvider");
+#if !TARGET_JVM //TargetJvmNotWorking - algorithms from System.Security assembly
// URL used in Canonicalization or Transform elements
CreateFromName ("http://www.w3.org/TR/2001/REC-xml-c14n-20010315", "System.Security.Cryptography.Xml.XmlDsigC14NTransform");
CreateFromName ("http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments", "System.Security.Cryptography.Xml.XmlDsigC14NWithCommentsTransform");
CreateFromName ("http://www.w3.org/2000/09/xmldsig# KeyValue/DSAKeyValue", "System.Security.Cryptography.Xml.DSAKeyValue");
CreateFromName ("http://www.w3.org/2000/09/xmldsig# KeyValue/RSAKeyValue", "System.Security.Cryptography.Xml.RSAKeyValue");
CreateFromName ("http://www.w3.org/2000/09/xmldsig# RetrievalMethod", "System.Security.Cryptography.Xml.KeyInfoRetrievalMethod");
+#if NET_2_0
+ CreateFromName ("http://www.w3.org/2001/04/xmlenc#sha256", "System.Security.Cryptography.SHA256Managed");
+ CreateFromName ("http://www.w3.org/2001/04/xmlenc#sha384", null);
+ CreateFromName ("http://www.w3.org/2001/04/xmlenc#sha512", "System.Security.Cryptography.SHA512Managed");
+
+ CreateFromName ("http://www.w3.org/2001/04/xmldsig-more#hmac-sha256", "System.Security.Cryptography.HMACSHA256");
+ CreateFromName ("http://www.w3.org/2001/04/xmldsig-more#hmac-sha384", "System.Security.Cryptography.HMACSHA384");
+ CreateFromName ("http://www.w3.org/2001/04/xmldsig-more#hmac-sha512", "System.Security.Cryptography.HMACSHA512");
+ CreateFromName ("http://www.w3.org/2001/04/xmldsig-more#hmac-ripemd160", "System.Security.Cryptography.HMACRIPEMD160");
+#endif
+#endif
}
[Test]
public void CreateFromName_UpperCase ()
{
CreateFromName ("SHA", "System.Security.Cryptography.SHA1CryptoServiceProvider");
+#if NET_2_0
CreateFromName ("SYSTEM.SECURITY.CRYPTOGRAPHY.TRIPLEDES", "System.Security.Cryptography.TripleDESCryptoServiceProvider");
CreateFromName ("HTTP://WWW.W3.ORG/2000/09/XMLDSIG#DSA-SHA1", "System.Security.Cryptography.DSASignatureDescription");
+#else
+ CreateFromName ("SYSTEM.SECURITY.CRYPTOGRAPHY.TRIPLEDES", null);
+ CreateFromName ("HTTP://WWW.W3.ORG/2000/09/XMLDSIG#DSA-SHA1", null);
+#endif
}
[Test]
public void CreateFromName_LowerCase ()
{
+#if NET_2_0
CreateFromName ("sha", "System.Security.Cryptography.SHA1CryptoServiceProvider");
CreateFromName ("system.security.cryptography.tripledes", "System.Security.Cryptography.TripleDESCryptoServiceProvider");
+#else
+ CreateFromName ("sha", null);
+ CreateFromName ("system.security.cryptography.tripledes", null);
+#endif
CreateFromName ("http://www.w3.org/2000/09/xmldsig#dsa-sha1", "System.Security.Cryptography.DSASignatureDescription");
}
[Test]
public void CreateFromName_MixedCase ()
{
+#if NET_2_0
CreateFromName ("ShA", "System.Security.Cryptography.SHA1CryptoServiceProvider");
CreateFromName ("SyStEm.SeCuRiTy.CrYpToGrApHy.TrIpLeDeS", "System.Security.Cryptography.TripleDESCryptoServiceProvider");
CreateFromName ("hTtP://wWw.W3.oRg/2000/09/xMlDsIg#dSa-sHa1", "System.Security.Cryptography.DSASignatureDescription");
+#else
+ CreateFromName ("ShA", null);
+ CreateFromName ("SyStEm.SeCuRiTy.CrYpToGrApHy.TrIpLeDeS", null);
+ CreateFromName ("hTtP://wWw.W3.oRg/2000/09/xMlDsIg#dSa-sHa1", null);
+#endif
}
// Tests created using "A Layer Man Guide to ASN.1" from RSA, page 19-20
[Test]
public void EncodeOID ()
{
- // OID starts with 0, 1 or 2\r
- Assert.AreEqual (oidETSI, CryptoConfig.EncodeOID ("0.4.0.0"), "OID starting with 0.");\r
- Assert.AreEqual (oidSHA1, CryptoConfig.EncodeOID ("1.3.14.3.2.26"), "OID starting with 1.");\r
+ // OID starts with 0, 1 or 2
+ Assert.AreEqual (oidETSI, CryptoConfig.EncodeOID ("0.4.0.0"), "OID starting with 0.");
+ Assert.AreEqual (oidSHA1, CryptoConfig.EncodeOID ("1.3.14.3.2.26"), "OID starting with 1.");
Assert.AreEqual (oidASN1CharacterModule, CryptoConfig.EncodeOID ("2.1.0.0.0"), "OID starting with 2.");
- // OID numbers can span multiple bytes\r
+ // OID numbers can span multiple bytes
Assert.AreEqual (oidmd5withRSAEncryption, CryptoConfig.EncodeOID ("1.2.840.113549.1.1.4"), "OID with numbers spanning multiple bytes");
}
// invalid OID - must start with 0, 1 or 2
// however it works with MS BCL
byte[] oid3 = CryptoConfig.EncodeOID ("3.0");
- byte[] res3 = { 0x06, 0x01, 0x78 };\r
+ byte[] res3 = { 0x06, 0x01, 0x78 };
Assert.AreEqual (res3, oid3, "OID: 3.0");
}
// invalid OID - second value < 40 for 0. and 1. (modulo 40)
// however it works with MS BCL
byte[] tooBigSecondPartOID = CryptoConfig.EncodeOID ("0.40");
- byte[] tooBigSecondPartRes = { 0x06, 0x01, 0x28 };\r
+ byte[] tooBigSecondPartRes = { 0x06, 0x01, 0x28 };
Assert.AreEqual (tooBigSecondPartRes, tooBigSecondPartOID, "OID: 0.40");
}
}
private void MapNameToOID (string name, string oid)
- {\r
+ {
Assert.AreEqual (oid, CryptoConfig.MapNameToOID (name), "oid(" + name + ")");
}
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");
+ MapNameToOID ("RIPEMD160", "1.3.36.3.2.1");
+ MapNameToOID ("System.Security.Cryptography.RIPEMD160", "1.3.36.3.2.1");
+ MapNameToOID ("System.Security.Cryptography.RIPEMD160Managed", "1.3.36.3.2.1");
#else
MapNameToOID ("SHA256", "2.16.840.1.101.3.4.1");
// MapNameToOID ("SHA-256", "2.16.840.1.101.3.4.1");
MapNameToOID ("RandomNumberGenerator", null);
MapNameToOID ("System.Security.Cryptography.RandomNumberGenerator", null);
MapNameToOID ("System.Security.Cryptography.KeyedHashAlgorithm", null);
-#if NET_2_0\r
- MapNameToOID ("HMAC", null);\r
- MapNameToOID ("System.Security.Cryptography.HMAC", null);\r
- MapNameToOID ("HMACMD5", null);\r
- MapNameToOID ("System.Security.Cryptography.HMACMD5", null);\r
- MapNameToOID ("HMACRIPEMD160", null);\r
- MapNameToOID ("System.Security.Cryptography.HMACRIPEMD160", null);\r
- MapNameToOID ("HMACSHA256", null);\r
- MapNameToOID ("System.Security.Cryptography.HMACSHA256", null);\r
- MapNameToOID ("HMACSHA384", null);\r
- MapNameToOID ("System.Security.Cryptography.HMACSHA384", null);\r
- MapNameToOID ("HMACSHA512", null);\r
- MapNameToOID ("System.Security.Cryptography.HMACSHA512", null);\r
-#endif\r
- MapNameToOID ("HMACSHA1", null);\r
- MapNameToOID ("System.Security.Cryptography.HMACSHA1", null);\r
+#if NET_2_0
+ MapNameToOID ("HMAC", null);
+ MapNameToOID ("System.Security.Cryptography.HMAC", null);
+ MapNameToOID ("HMACMD5", null);
+ MapNameToOID ("System.Security.Cryptography.HMACMD5", null);
+ MapNameToOID ("HMACRIPEMD160", null);
+ MapNameToOID ("System.Security.Cryptography.HMACRIPEMD160", null);
+ MapNameToOID ("HMACSHA256", null);
+ MapNameToOID ("System.Security.Cryptography.HMACSHA256", null);
+ MapNameToOID ("HMACSHA384", null);
+ MapNameToOID ("System.Security.Cryptography.HMACSHA384", null);
+ MapNameToOID ("HMACSHA512", null);
+ MapNameToOID ("System.Security.Cryptography.HMACSHA512", null);
+#endif
+ MapNameToOID ("HMACSHA1", null);
+ MapNameToOID ("System.Security.Cryptography.HMACSHA1", null);
MapNameToOID ("MACTripleDES", null);
MapNameToOID ("System.Security.Cryptography.MACTripleDES", null);
// non existing algo should return null (without exception)
public void MapNameToOID_UpperCase ()
{
MapNameToOID ("SHA1", "1.3.14.3.2.26");
+#if NET_2_0
MapNameToOID ("SYSTEM.SECURITY.CRYPTOGRAPHY.MD5CRYPTOSERVICEPROVIDER", "1.2.840.113549.2.5");
+#else
+ MapNameToOID ("SYSTEM.SECURITY.CRYPTOGRAPHY.MD5CRYPTOSERVICEPROVIDER", null);
+#endif
}
[Test]
public void MapNameToOID_LowerCase ()
{
+#if NET_2_0
MapNameToOID ("sha1", "1.3.14.3.2.26");
MapNameToOID ("system.security.cryptography.md5cryptoserviceprovider", "1.2.840.113549.2.5");
+#else
+ MapNameToOID ("sha1", null);
+ MapNameToOID ("system.security.cryptography.md5cryptoserviceprovider", null);
+#endif
}
[Test]
public void MapNameToOID_MixedCase ()
{
+#if NET_2_0
MapNameToOID ("sHa1", "1.3.14.3.2.26");
MapNameToOID ("SySteM.SeCuRiTy.CrYpToGrApHy.Md5cRyPtOsErViCePrOvIdEr", "1.2.840.113549.2.5");
+#else
+ MapNameToOID ("sHa1", null);
+ MapNameToOID ("SySteM.SeCuRiTy.CrYpToGrApHy.Md5cRyPtOsErViCePrOvIdEr", null);
+#endif
}
[Test]