title: need a help in order to Encrypt/decrypt file using bouncy castle in c#
body: <p>please help;</p>
  
  <p>i have creted a server application that generate a x.509v3 certificates. than, i export a publique and private key in .txt file ( format hex, or pem) ;</p>
  
  <p>i must now encrypt files in another client application, my problem is that i can't do this using a public key directly , for this i have written a following code:</p>
  
  <pre><code>        string fichier = @"C:\\Users\\Me\\Documents\\marie.docx";
          FileInfo f = new FileInfo(fichier);
  
  
          byte[] buffer = new byte[(int)f.Length];
  
          System.IO.StreamReader strem = new System.IO.StreamReader(fichier);
          String line = strem.ReadToEnd();
          strem.Close();
  
          IBufferedCipher cipher = CipherUtilities.GetCipher("RSA/ECB/PKCS1Padding");
  
          string str = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7cXmz0lTtzEuFAP0rR1f//RZZ8dGxa26I/LwJiNFqJULDvLjmiEHs+u+2gjc3Qm1cwcusuP+akCJIsGyn+9joEbEUKCaJOXbXsuqFKWFlsnfoCGTT8M1a5J2SNixsrLCim9P+qoGfml7JONUhWoiUVYqagRG4WgFmQHonttdnWEqk5yHtXp4ZzL+Bw54IaliyEzigBMW4k0rwMceR31MGnGGcplOynX6Ga5J3HZvLm2XoUQ6PAWw19yjmjiurwBugDOA2NdLOOR96Jxv39Kv/MyGXjjN3Z2hEsSVhHQ4j9RlEg0zsMhXoHJ/MsoVr5WKhEpCuuwp8IuQmwAFW1GoEwIDAQAB";
  
          char[] cArray = str.ToCharArray();
          byte[] pub_Array = new byte[cArray.Length];
  
          for (int j = 0; j &lt; cArray.Length; j++)
              pub_Array[j] = (byte)cArray[j];
  
          KeyParameter par = new KeyParameter(pub_Array);
  
          cipher.Init(false, par);
  
          //byte[] output = cipher.DoFinal(data);
  
          int blockSize = cipher.GetBlockSize();
  
          int outputSize = cipher.GetOutputSize(buffer.Length);
  
  
          int leavedSize = buffer.Length % blockSize;
          int blocksSize = leavedSize != 0 ? buffer.Length / blockSize + 1 : buffer.Length / blockSize;
          byte[] raw = new byte[outputSize * blocksSize];
          int i = 0;
  
          while (buffer.Length - i * blockSize &gt; 0)
          {
              if (buffer.Length - i * blockSize &gt; blockSize)
                  cipher.DoFinal(buffer, i * blockSize, blockSize,
                                 raw, i * outputSize);
              else
                  cipher.DoFinal(buffer, i * blockSize,
                                 buffer.Length - i * blockSize,
                                 raw, i * outputSize);
              i++;
          }
  
          // Ecriture du fichier chiffré sur le disque dur
  
          StreamWriter envfos = null;
  
          using (envfos = new StreamWriter("fichier_chiffrer.txt"))
          {
              envfos.Write(raw);
  
          }
  
          envfos.Close();
  </code></pre>
  
  <p>i have an </p>
  
  <pre><code>exception in : cipher.Init(false,par); &lt;&lt; Impossible d'effectuer un cast d'un objet de type 'Org.BouncyCastle.Crypto.Parameters.KeyParameter' en type 'Org.BouncyCastle.Crypto.AsymmetricKeyParameter'.
  </code></pre>
  
  <p>Help please </p>
  
  <p>any documentation in c# please;</p>
  
  <p>think's in advance</p>
  
  <p>Cordialement marie;</p>