Пример #1
0
        public void AsymmetricAdapterUsageTests(AsymmetricAdatperTheoryData theoryData)
        {
            var context = TestUtilities.WriteHeader($"{this}.AsymmetricAdapterUsageTests", theoryData);

            byte[]        bytes         = Encoding.UTF8.GetBytes("var context = TestUtilities.WriteHeader($'{ this}.AsymmetricAdapterUsageTests', theoryData);");
            HashAlgorithm hashAlgorithm = CryptoProviderFactory.Default.CreateHashAlgorithm(theoryData.HashAlorithmString);

            try
            {
#if NET461 || NETCOREAPP2_1
                AsymmetricAdapter asymmetricdapter = new AsymmetricAdapter(theoryData.SecurityKey, theoryData.Algorithm, hashAlgorithm, SupportedAlgorithms.GetHashAlgorithmName(theoryData.Algorithm), true);
#else
                AsymmetricAdapter asymmetricdapter = new AsymmetricAdapter(theoryData.SecurityKey, theoryData.Algorithm, hashAlgorithm, true);
#endif
                byte[] signature = asymmetricdapter.Sign(bytes);
                if (!asymmetricdapter.Verify(bytes, signature))
                {
                    context.AddDiff($"Verify failed for test: {theoryData.TestId}");
                }

                theoryData.ExpectedException.ProcessNoException(context);
            }
            catch (Exception ex)
            {
                theoryData.ExpectedException.ProcessException(ex, context);
            }

            TestUtilities.AssertFailIfErrors(context);
        }