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); }
/// <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); }
public RSAParameters GetParameters() => RsaKeyEncoder.Decode(Key);
/// <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)) { }