コード例 #1
0
        public bool Verify(byte[] signature, byte[] securedInput, object key)
        {
            if (key is CngKey)
            {
                var publicKey = (CngKey)key;

                try
                {
                    return(RsaPss.Verify(securedInput, signature, publicKey, Hash, saltSize));
                }
                catch (CryptographicException e)
                {
                    return(false);
                }
            }

            if (key is RSACryptoServiceProvider)
            {
                //This is for backward compatibility only with 2.x
                //To be removed in 3.x
                var publicKey = RsaKey.New(((RSACryptoServiceProvider)key).ExportParameters(false));

                try
                {
                    return(RsaPss.Verify(securedInput, signature, publicKey, Hash, saltSize));
                }
                catch (CryptographicException e)
                {
                    return(false);
                }
            }

            if (key is RSA)
            {
                var publicKey = (RSA)key;

                return(publicKey.VerifyData(securedInput, signature, HashAlgorithm, RSASignaturePadding.Pss));
            }

            throw new ArgumentException("RsaUsingSha with PSS padding alg expects key to be of either CngKey or RSA types.");
        }
コード例 #2
0
        public byte[] Sign(byte[] securedInput, object key)
        {
            if (key is CngKey)
            {
                var privateKey = (CngKey)key;

                try
                {
                    return(RsaPss.Sign(securedInput, privateKey, Hash, saltSize));
                }
                catch (CryptographicException e)
                {
                    throw new JoseException("Unable to sign content.", e);
                }
            }

            if (key is RSACryptoServiceProvider)
            {
                //This is for backward compatibility only with 2.x
                //To be removed in 3.x
                var privateKey = RsaKey.New(((RSACryptoServiceProvider)key).ExportParameters(true));

                try
                {
                    return(RsaPss.Sign(securedInput, privateKey, Hash, saltSize));
                }
                catch (CryptographicException e)
                {
                    throw new JoseException("Unable to sign content.", e);
                }
            }

            if (key is RSA)
            {
                var privateKey = (RSA)key;
                return(privateKey.SignData(securedInput, HashAlgorithm, RSASignaturePadding.Pss));
            }

            throw new ArgumentException("RsaUsingSha with PSS padding alg expects key to be of either CngKey or RSA types.");
        }