public Response(string certificateStr) { RSAPKCS1SHA256SignatureDescription.Init(); //init the SHA256 crypto provider (for needed for .NET 4.0 and lower) _certificate = new Certificate(); _certificate.LoadCertificate(certificateStr); }
public void TestInitialize() { RSAPKCS1SHA256SignatureDescription.AddSupportForNET4(); // has to set specific culture, because some tests are testing culture-specific parsing of strings Thread.CurrentThread.CurrentCulture = new CultureInfo("cs-CZ"); }
public Utils() { // ručně musíme přidat podporu pro podpisy RSA-SHA-256, .NET framework ji standardně nepodporuje // pro starší verze .NET frameworku je navíc potřeba doinstalovat knihovny z adresy http://clrsecurity.codeplex.com/wikipage?title=Security.Cryptography.RSAPKCS1SHA256SignatureDescription&referringTitle=Security.Cryptography.dll RSAPKCS1SHA256SignatureDescription desc = new RSAPKCS1SHA256SignatureDescription(); System.Security.Cryptography.CryptoConfig.AddAlgorithm(desc.GetType(), "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"); }
public void RSAPKCS1SHA256RoundTripTest() { using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048)) { RSAPKCS1SHA256SignatureDescription sd = new RSAPKCS1SHA256SignatureDescription(); using (HashAlgorithm digestAlgorithm = sd.CreateDigest()) { // Create some data to sign RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); byte[] data = new byte[1025]; rng.GetBytes(data); byte[] hash = digestAlgorithm.ComputeHash(data); // Sign the data AsymmetricSignatureFormatter formatter = sd.CreateFormatter(rsa); byte[] signature = formatter.CreateSignature(hash); Assert.IsNotNull(signature, "Failed to create a signature"); // Verify the signature AsymmetricSignatureDeformatter deformatter = sd.CreateDeformatter(rsa); Assert.IsTrue(deformatter.VerifySignature(hash, signature), "Failed to verify signature"); } } }
public Utils() { // ručně musíme přidat podporu pro podpisy RSA-SHA-256, .NET framework ji standardně nepodporuje // pro starší verze .NET frameworku je navíc potřeba doinstalovat knihovny z adresy http://clrsecurity.codeplex.com/wikipage?title=Security.Cryptography.RSAPKCS1SHA256SignatureDescription&referringTitle=Security.Cryptography.dll RSAPKCS1SHA256SignatureDescription desc = new RSAPKCS1SHA256SignatureDescription(); System.Security.Cryptography.CryptoConfig.AddAlgorithm(desc.GetType(), "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"); }
public AuthRequest(string issuer, string assertionConsumerServiceUrl) { RSAPKCS1SHA256SignatureDescription.Init(); //init the SHA256 crypto provider (for needed for .NET 4.0 and lower) _id = "_" + System.Guid.NewGuid().ToString(); _issue_instant = DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ", System.Globalization.CultureInfo.InvariantCulture); _issuer = issuer; _assertionConsumerServiceUrl = assertionConsumerServiceUrl; }
// ReSharper disable once UnusedParameter.Local static void Main(string[] args) { RSAPKCS1SHA256SignatureDescription.AddSupportForNET4(); //SignAndSend(); Task.WaitAll(SimpleRegistrationProcessTest()); Console.WriteLine(@"Press any key to finish ..."); Console.ReadKey(); }
public void RSAPKCS1SHA256SignatureCreateTest() { RSAPKCS1SHA256SignatureDescription sd = new RSAPKCS1SHA256SignatureDescription(); using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) { // We should be using the PKCS1 signature deformatter AsymmetricSignatureDeformatter deformatter = sd.CreateDeformatter(rsa); Assert.IsInstanceOfType(deformatter, typeof(RSAPKCS1SignatureDeformatter)); // We should be using the PKCS1 signature formatter AsymmetricSignatureFormatter formatter = sd.CreateFormatter(rsa); Assert.IsInstanceOfType(formatter, typeof(RSAPKCS1SignatureFormatter)); } // We should be using SHA256Managed for hashing using (HashAlgorithm digestAlgorithm = sd.CreateDigest()) { Assert.IsInstanceOfType(digestAlgorithm, typeof(SHA256Managed)); } }
public void RSAPKCS1SHA256SignatureDescriptionPropertiesTest() { RSAPKCS1SHA256SignatureDescription sd = new RSAPKCS1SHA256SignatureDescription(); // We should be using RSAPKCS1 for formatting Assert.AreEqual(typeof(RSAPKCS1SignatureDeformatter).FullName, sd.DeformatterAlgorithm); Assert.AreEqual(typeof(RSAPKCS1SignatureFormatter).FullName, sd.FormatterAlgorithm); // We should be using SHA256 as the digest algorithm Assert.AreEqual(typeof(SHA256Managed).FullName, sd.DigestAlgorithm); using (HashAlgorithm digestAlgorithm = (HashAlgorithm)CryptoConfig.CreateFromName(sd.DigestAlgorithm)) { Assert.IsInstanceOfType(digestAlgorithm, typeof(SHA256Managed)); } // We should be using RSACryptoServiceProvider as the signature algorithm Assert.AreEqual(typeof(RSACryptoServiceProvider).FullName, sd.KeyAlgorithm); using (AsymmetricAlgorithm keyAlgorithm = (AsymmetricAlgorithm)CryptoConfig.CreateFromName(sd.KeyAlgorithm)) { Assert.IsInstanceOfType(keyAlgorithm, typeof(RSACryptoServiceProvider)); } }
public Response(byte[] certificateBytes) { RSAPKCS1SHA256SignatureDescription.Init(); //init the SHA256 crypto provider (for needed for .NET 4.0 and lower) _certificate = new X509Certificate2(certificateBytes); }