title: JSch addIdentity - How to pass private and public key strings vs. file path
body: <p>There are a lot of examples on this, but none of them show a working example on how use the .ppk public/private file components in a string form converted to a <code>byte[]</code> and used with the <code>JSch.addIdentity(String,byte[],byte[],byte[])</code> method. Can someone look at the following method and let me know where I'm going wrong. It doesn't like the strings converted to a <code>byte[]</code>. The strings are not in full for security reasons, but I think you'll get the point of what I'm trying accomplish with this. Unfortunately, I'm stuck using strings for this since I cannot use the .ppk file directly.</p>
  <pre><code>public void InitChannelSftp() throws JSchException {
      JSch ssh = new JSch();
      session_ = ssh.getSession(userName_, host_, port_);
      session_.setConfig(&quot;StrictHostKeyChecking&quot;, &quot;no&quot;);
      
      String passPhrase= &quot;trustNoOne&quot;;
  
      String privateKey= &quot;-----BEGIN RSA PRIVATE KEY-----\n&quot; +
              &quot;hvbytegNktMU05bc3QlCrSs+YHkMAvZRkzcjaXDdcKDfSZyDqcFHfkup1N6CMDg4\n&quot; +
              &quot;yZh0ou+7G8jDQtn29YoAO0tpEW4EGQiI6918iMk22012ytcsCnM80/hj1JbVa4St\n&quot; +
              &quot;1StZKJtBYSu1bRZCpFPygditUGc9pZhDWfgDxLTzQdDMcmdvMb9AgpNKZAz8n0OR\n&quot; +
              &quot;2tuGPAogbt8e48ad9H7IYuikhIqQU42DkrAqRPJDUZqP3gGdzwstuDPl1dwrRaCs\n&quot; +
              &quot;vTynsEMDCjVjNyxRK9sbBO/BwFTaFRM2oN4BvCbfbQKyhRrXZ1gjNMv1P5GxchKj\n&quot;+
              &quot;-----END RSA PRIVATE KEY-----\n&quot;;
  
      String publicKey= &quot;-----BEGIN SH2 PUBLIC KEY-----\n&quot; +
              &quot;AAAAB3NzaC1yc2EAAAABJQAAAQEA6wXxLoqF70gkd2hURVlmq+iPCBPmkZ6IwCST\n&quot; +
              &quot;nlxHY/Jc0izbn+6hyFUZmS53LN9CJyjjVvU+UAWapU2tTJKwO6aI8xcKmtBjdDeS\n&quot; +
              &quot;GJgh6C+srGFlbNTXzV8sMmGEQirLyTOMwGviRFOhKn5/bUbqpw==\n&quot; +
              &quot;-----BEGIN SH2 PUBLIC KEY-----\n&quot;
  
  
      ssh.addIdentity(
          &quot;Test Conn&quot;, privateKey.getBytes(StandardCharsets.US_ASCII),
          publicKey.getBytes(StandardCharsets.US_ASCII), passPhrase.getBytes());
  
      session_.connect();
      channel_ = session_.openChannel(&quot;sftp&quot;);
      channel_.connect();
      ChannelSftp sftp_ = (ChannelSftp) channel_;
  }
  </code></pre>
  <p>Error:</p>
  <blockquote>
  <p>com.jcraft.jsch.JSchException: invalid privatekey: [B@25be7b63</p>
  </blockquote>