Example #1
0
        /// <summary>
        /// Creates a new instance of a specified algorithm-class.
        /// </summary>
        /// <param name="algorithm">The algorithm to use.</param>
        /// <param name="operation">The operations required to be supported.</param>
        /// <returns>Instance of the right algorithm class guaranted to support the given operations (i.e. implementing the correct interfaces).</returns>
        public static AlgorithmBase Create(KeyAlgorithm algorithm, KeyOperation operation)
        {
            Type          type     = Type.GetType("OpenPGP." + algorithm.ToString() + "Algorithm");
            AlgorithmBase instance = (AlgorithmBase)Activator.CreateInstance(type);

            return(instance);
        }
Example #2
0
        /// <summary>
        /// Get the JWS name of the <paramref name="algorithm"/>.
        /// </summary>
        /// <param name="algorithm">The algorithm.</param>
        /// <returns></returns>
        public static string ToJwsAlgorithm(this KeyAlgorithm algorithm)
        {
            if (!Enum.IsDefined(typeof(KeyAlgorithm), algorithm))
            {
                throw new ArgumentException(nameof(algorithm));
            }

            return(algorithm.ToString());
        }