Example #1
0
        public RsaPrivateKey(RSAParameters parameters)
        {
            if (parameters.D == null ||
                parameters.DP == null ||
                parameters.DQ == null ||
                parameters.InverseQ == null ||
                parameters.P == null ||
                parameters.Q == null
                )
            {
                throw new ArgumentException("It looks like provided parameter is not private key", nameof(parameters));
            }

            Key = RsaKeyEncoder.Encode(parameters);
        }
Example #2
0
        /// <summary>
        /// Constructor accepts parameters, only stores public part of the key
        /// </summary>
        /// <param name="parameters">RSA parameters</param>
        public RsaPublicKey(RSAParameters parameters)
        {
            if (parameters.Modulus == null ||
                parameters.Exponent == null
                )
            {
                throw new ArgumentException("It looks like provided parameters are not set.", nameof(parameters));
            }

            parameters.D        = null;
            parameters.DP       = null;
            parameters.DQ       = null;
            parameters.InverseQ = null;
            parameters.P        = null;
            parameters.Q        = null;

            Key = RsaKeyEncoder.Encode(parameters);
        }
Example #3
0
 public RSAParameters GetParameters() => RsaKeyEncoder.Decode(Key);
Example #4
0
 /// <summary>
 /// Constructor, accepts encoded key, only stores public part of the key
 /// </summary>
 /// <param name="key">Encoded key</param>
 public RsaPublicKey(string key) : this(RsaKeyEncoder.Decode(key))
 {
 }