private void SignData(RSACryptoServiceProviderProxy rsaCspProxy, ExpectedException ee)
        {
            try
            {
#if NETCOREAPP1_0
                rsaCspProxy.SignData(input, _hashAlgorithm.Name);
#else
                rsaCspProxy.SignData(input, _hashAlgorithm);
#endif
                ee.ProcessNoException();
            }
            catch (Exception ex)
            {
                ee.ProcessException(ex);
            }
        }
Пример #2
0
        public void RSASignVerifyData(RSACryptoServiceProviderProxyTheoryData theoryData)
        {
            var context = TestUtilities.WriteHeader($"{this}.RSASignVerifyData", theoryData);

            try
            {
                var proxy          = new RSACryptoServiceProviderProxy(theoryData.RsaCryptoServiceProvider);
                var signatureProxy = proxy.SignData(theoryData.Input, theoryData.HashAlgorithm);
                var signatureRsa   = theoryData.RsaCryptoServiceProvider.SignData(theoryData.Input, theoryData.HashAlgorithm);
                IdentityComparer.AreBytesEqual(signatureProxy, signatureRsa, context);
                if (!proxy.VerifyData(theoryData.Input, theoryData.HashAlgorithm, signatureRsa))
                {
                    context.AddDiff("!proxy.VerifyData(theoryData.Input, theoryData.HashAlgorithm, signatureRsa)");
                }

                if (!theoryData.RsaCryptoServiceProvider.VerifyData(theoryData.Input, theoryData.HashAlgorithm, signatureProxy))
                {
                    context.AddDiff("!theoryData.RsaCryptoServiceProvider.VerifyData(theoryData.Input, theoryData.HashAlgorithm, signatureProxy)");
                }
            }
            catch (Exception ex)
            {
                theoryData.ExpectedException.ProcessException(ex, context);
            }

            TestUtilities.AssertFailIfErrors(context);
        }
 private void SignData(RSACryptoServiceProviderProxy rsaCspProxy, ExpectedException ee)
 {
     try
     {
         rsaCspProxy.SignData(input, _hashAlgorithm);
         ee.ProcessNoException();
     }
     catch (Exception ex)
     {
         ee.ProcessException(ex);
     }
 }
Пример #4
0
        /// <summary>
        /// Produces a signature over the 'input' using the <see cref="AsymmetricSecurityKey"/> and algorithm passed to <see cref="AsymmetricSignatureProvider( SecurityKey, string, bool )"/>.
        /// </summary>
        /// <param name="input">The bytes to be signed.</param>
        /// <returns>A signature over the input.</returns>
        /// <exception cref="ArgumentNullException">'input' is null. </exception>
        /// <exception cref="ArgumentException">'input.Length' == 0. </exception>
        /// <exception cref="ObjectDisposedException">If <see cref="AsymmetricSignatureProvider.Dispose(bool)"/> has been called. </exception>
        /// <exception cref="InvalidOperationException">If the internal <see cref="AsymmetricSignatureProvider"/> is null. This can occur if the constructor parameter 'willBeUsedforSigning' was not 'true'.</exception>
        /// <exception cref="InvalidOperationException">If the internal <see cref="HashAlgorithm"/> is null. This can occur if a derived type deletes it or does not create it.</exception>
        public override byte[] Sign(byte[] input)
        {
            if (input == null || input.Length == 0)
            {
                throw LogHelper.LogArgumentNullException("input");
            }

            if (_disposed)
            {
                throw LogHelper.LogExceptionMessage(new ObjectDisposedException(GetType().ToString()));
            }

#if NETSTANDARD1_4
            if (_rsa != null)
            {
                return(_rsa.SignData(input, _hashAlgorithm, RSASignaturePadding.Pkcs1));
            }
            else if (_ecdsa != null)
            {
                return(_ecdsa.SignData(input, _hashAlgorithm));
            }
#else
            if (_rsaCryptoServiceProvider != null)
            {
                return(_rsaCryptoServiceProvider.SignData(input, _hashAlgorithm));
            }
            else if (_rsaCryptoServiceProviderProxy != null)
            {
                return(_rsaCryptoServiceProviderProxy.SignData(input, _hashAlgorithm));
            }
            else if (_ecdsa != null)
            {
                return(_ecdsa.SignData(input));
            }
#endif
            throw LogHelper.LogExceptionMessage(new InvalidOperationException(LogMessages.IDX10644));
        }