/// <summary> /// Creates a SimpleRSADigitalSigner based on the path of the X509 Cert, password, and hashing algorithm. /// </summary> /// <param name="path"> /// The file path of the cert. /// </param> /// <param name="password"> /// The password required to open the X509 Cert. /// </param> /// <param name="hashAlgorithm"> /// A supported requested hashing algorithm, defaulting to MD5 if none is passed. /// </param> public SimpleRSADigitalSigner(string path, string password, SimplerHasher.HashType hashAlgorithm = SimplerHasher.HashType.MD5) : this(hashAlgorithm) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } this.Certificate = new X509Certificate2(path, password, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable); //Retrieve the public and private RSA keys early. //Even though this is stored in the cert, let's kept the logic simple and assign these properites when we have either key. this.PrivateKey = Certificate.PrivateKey as RSACryptoServiceProvider; this.PublicKey = Certificate.PublicKey.Key as RSACryptoServiceProvider; if (this.PrivateKey == null) { throw new InvalidCastException("The certificate's private key is not RSA based."); } if (this.PublicKey == null) { throw new InvalidCastException("The certificate's public key is not RSA based."); } }
/// <summary> /// Creates a SimpleRSADigitalSigner based on the hashing algorithm. They PublicKey and PrivateKey properties must be set manually. /// </summary> /// <param name="hashAlgorithm"> /// A supported requested hashing algorithm, defaulting to MD5 if none is passed. /// </param> public SimpleRSADigitalSigner(SimplerHasher.HashType hashAlgorithm = SimplerHasher.HashType.MD5, bool fOAEP = true) { this.HashAlgorithm = hashAlgorithm; this.fOAEP = fOAEP; }