/// <summary>
        /// Converts a WebKey of type RSA or RSAHSM to a RSA parameter object
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="includePrivateParameters">Tells if private material
        /// must be included.</param>
        /// <returns>An RSA parameter</returns>
        public static RSAParameters ToRSAParameters(this RsaParams parameters,
                                                    bool includePrivateParameters = true)
        {
            KeyEx.VerifyNonZero(parameters.N);
            KeyEx.VerifyNonZero(parameters.E);
            if (!includePrivateParameters)
            {
                return(new RSAParameters {
                    Modulus = KeyEx.RemoveLeadingZeros(parameters.N),
                    Exponent = KeyEx.ForceLength(parameters.E, 4)
                });
            }
            var num = KeyEx.RemoveLeadingZeros(parameters.N).Length * 8;

            return(new RSAParameters {
                Modulus = KeyEx.RemoveLeadingZeros(parameters.N),
                Exponent = KeyEx.ForceLength(parameters.E, 4),
                D = KeyEx.ForceLength(parameters.D, num / 8),
                DP = KeyEx.ForceLength(parameters.DP, num / 16),
                DQ = KeyEx.ForceLength(parameters.DQ, num / 16),
                InverseQ = KeyEx.ForceLength(parameters.QI, num / 16),
                P = KeyEx.ForceLength(parameters.P, num / 16),
                Q = KeyEx.ForceLength(parameters.Q, num / 16)
            });
        }
 /// <summary>
 /// Remove leading zeros from all RSA parameters.
 /// </summary>
 public static RsaParams Canonicalize(this RsaParams parameters)
 {
     return(new RsaParams {
         N = KeyEx.RemoveLeadingZeros(parameters.N),
         E = KeyEx.RemoveLeadingZeros(parameters.E),
         D = KeyEx.RemoveLeadingZeros(parameters.D),
         DP = KeyEx.RemoveLeadingZeros(parameters.DP),
         DQ = KeyEx.RemoveLeadingZeros(parameters.DQ),
         QI = KeyEx.RemoveLeadingZeros(parameters.QI),
         P = KeyEx.RemoveLeadingZeros(parameters.P),
         Q = KeyEx.RemoveLeadingZeros(parameters.Q),
         T = parameters.T
     });
 }