/// <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(); } }
/// <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."); }
/// <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(); } }