/// <summary> /// Creates the RSA provider. Providing either <c>Public Key</c> or <c>Private Key</c> is OK. /// </summary> /// <param name="rsaKeys">The RSA keys.</param> /// <returns></returns> public static RSACryptoServiceProvider CreateRsaProvider(this IRsaKeys rsaKeys) { RSACryptoServiceProvider rsaProvider = null; if (rsaKeys != null) { try { rsaProvider = new RSACryptoServiceProvider(rsaKeys.DoubleWordKeySize); if (rsaKeys.PrivateKey != null) { rsaProvider.ImportCspBlob(rsaKeys.PrivateKey); } else { if (rsaKeys.PublicKey != null) { rsaProvider.ImportCspBlob(rsaKeys.PublicKey); } } } catch (Exception ex) { throw ex.Handle(rsaKeys); } } return(rsaProvider); }
/// <summary> /// Creates the RSA public provider. /// </summary> /// <param name="rsaKeys">The RSA keys.</param> /// <returns></returns> public static RSACryptoServiceProvider CreateRsaPublicProvider(this IRsaKeys rsaKeys) { try { rsaKeys.CheckNullObject(nameof(rsaKeys)); rsaKeys.PublicKey.CheckNullOrEmpty(nameof(rsaKeys.PublicKey)); var rsa = new RSACryptoServiceProvider(rsaKeys.DoubleWordKeySize); rsa.ImportCspBlob(Convert.FromBase64String(rsaKeys.PublicKey)); return(rsa); } catch (Exception ex) { throw ex.Handle(rsaKeys); } }
public Rsa(IRsaKeys rsaKeys) { _rsaKeys = rsaKeys; }