title: Transforming Ruby code from apple documentation (iPhoneOTAConfiguration) to Java
body: <p>I am working web application for iOS MDM.
  In that, payload within mobileconfig is to be encrypted before sending to device.
  Apple documentation givex following code as example, its in Ruby and working fine.
  But, I am not able to implement the same in Java.</p>
  
  <pre><code>OpenSSL::PKCS7.encrypt(p7sign.certificates,
  payload, OpenSSL::Cipher::Cipher::new("des-ede3-cbc"),
  OpenSSL::PKCS7::BINARY)
  </code></pre>
  
  <p>Java code I used is as:</p>
  
  <pre><code>     PublicKey publicKey = x509cert.getPublicKey();
      //publinKey is key extracted from iOS device response stream
  
      Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
      cipher.init(Cipher.ENCRYPT_MODE, publicKey);
      clearText = payloadContents.getBytes();
      //payloadContents are contents to be encrypyted
      cipherText = cipher.doFinal(clearText);
  </code></pre>
  
  <p>error after executing this is </p>
  
  <p>java.security.InvalidKeyException: No installed provider supports this key: sun.security.rsa.RSAPublicKeyImpl
      at javax.crypto.Cipher.a(DashoA13*..)
      at javax.crypto.Cipher.init(DashoA13*..)
      at javax.crypto.Cipher.init(DashoA13*..)</p>