コード例 #1
0
ファイル: CngUtilities.cs プロジェクト: sramos30/PCLCrypto
        /// <summary>
        /// Gets the BCrypt (or NCrypt) algorithm identifier for an asymmetric algorithm.
        /// </summary>
        /// <param name="algorithm">The PCL asymmetric algorithm.</param>
        /// <returns>The BCrypt/NCrypt compatible algorithm identifier.</returns>
        internal static string GetAlgorithmId(AsymmetricAlgorithm algorithm)
        {
            switch (algorithm.GetName())
            {
            case AsymmetricAlgorithmName.Dsa:
                return(BCrypt.AlgorithmIdentifiers.BCRYPT_DSA_ALGORITHM);

            case AsymmetricAlgorithmName.Ecdsa:
                switch (GetAlgorithmKeySize(algorithm))
                {
                case 256:
                    return(BCrypt.AlgorithmIdentifiers.BCRYPT_ECDSA_P256_ALGORITHM);

                case 384:
                    return(BCrypt.AlgorithmIdentifiers.BCRYPT_ECDSA_P384_ALGORITHM);

                case 521:
                    return(BCrypt.AlgorithmIdentifiers.BCRYPT_ECDSA_P521_ALGORITHM);

                default:
                    throw new ArgumentOutOfRangeException();
                }

            case AsymmetricAlgorithmName.Rsa:
            case AsymmetricAlgorithmName.RsaSign:
                return(BCrypt.AlgorithmIdentifiers.BCRYPT_RSA_ALGORITHM);

            default:
                throw new NotSupportedException();
            }
        }
コード例 #2
0
        /// <summary>Initializes a new instance of the <see cref="RsaAsymmetricKeyAlgorithmProvider"/> class.</summary>
        /// <param name="algorithm">The algorithm.</param>
        public RsaAsymmetricKeyAlgorithmProvider(AsymmetricAlgorithm algorithm)
            : base(algorithm)
        {
            var algorithmName = algorithm.GetName();

            Requires.Argument(algorithmName == AsymmetricAlgorithmName.Rsa || algorithmName == AsymmetricAlgorithmName.RsaSign, nameof(algorithm), "RSA algorithm expected.");
        }
コード例 #3
0
        /// <inheritdoc />
        public IAsymmetricKeyAlgorithmProvider OpenAlgorithm(AsymmetricAlgorithm algorithm)
        {
            switch (algorithm.GetName())
            {
            case AsymmetricAlgorithmName.Ecdsa:
                return(new ECDsaKeyProvider(algorithm));

            case AsymmetricAlgorithmName.Rsa:
            case AsymmetricAlgorithmName.RsaSign:
                return(new RsaAsymmetricKeyAlgorithmProvider(algorithm));

            case AsymmetricAlgorithmName.Dsa:
            default:
                throw new NotSupportedException();
            }
        }