title: How to encrypt using a X509 public cert with Android?
body: <p>I am trying to encrypt a text file using a .pfx certificate file using :</p>
  
  <pre><code>public void EncryptUsingPublicKey(File in, File out, File publicKeyFile) throws IOException, GeneralSecurityException {
  
      byte[] encodedKey = new byte[(int)publicKeyFile.length()];
      new FileInputStream(publicKeyFile).read(encodedKey);
  
      // create public key
      X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(encodedKey);
      KeyFactory kf = KeyFactory.getInstance("RSA");
      PublicKey pk = kf.generatePublic(publicKeySpec);
  
      FileInputStream is = new FileInputStream(in);
      Cipher pkCipher = Cipher.getInstance("RSA");
      pkCipher.init(Cipher.ENCRYPT_MODE, pk);
      CipherOutputStream os = new CipherOutputStream(new FileOutputStream(out), pkCipher);
      copy(is, os);
      os.close();
  }
  </code></pre>
  
  <p>I have two problems:</p>
  
  <ol>
  <li>Where should I store the .pfx file on the device?</li>
  <li>Is this function correct?</li>
  </ol>