title: Implementing Hybrid Encryption?
body: <p>I already have an asymmetric algorithm implemented in an MVC C# Application, however I would like to modify the encryption method so that I make use of both symmetric and asymmetric encryption (AKA Hybrid encryption). Any idea how I can do this?</p>
  
  <p>Asymmetric encrypt:</p>
  
  <pre><code>public string AsymmEncrypt(int accId, string input, string publickey)
      {
          Account a = new UserRepository().GetAccountById(accId);
          RSACryptoServiceProvider myAlg = new RSACryptoServiceProvider();
          CspParameters cspParams = new CspParameters();
          publickey = new UserRepository().PublicKeyByAccountId(accId);
          cspParams.KeyContainerName = publickey;
          myAlg = new RSACryptoServiceProvider(cspParams);
  
          byte[] cipher = myAlg.Encrypt(UTF8Encoding.UTF8.GetBytes(input), true);
          return Convert.ToBase64String(cipher);
      }
  </code></pre>
  
  <p>Asymmetric decrypt:</p>
  
  <pre><code>        public string AsymmDecrypt(int accId, string input, string privatekey)
      {
          Account a = new UserRepository().GetAccountById(accId);
          RSACryptoServiceProvider myAlg = new RSACryptoServiceProvider();
          CspParameters cspParams = new CspParameters();
          privatekey = new UserRepository().PrivateKeyByAccountId(accId);
  
          byte[] cipher = myAlg.Decrypt(Convert.FromBase64String(input), true);
          return UTF8Encoding.UTF8.GetString(cipher);
      }
  </code></pre>