This discussion is archived
0 Replies Latest reply: Jan 11, 2013 5:25 AM by 983611 RSS

Connect to SFTP using certificate and private key using Java (11.2 Oracle)

983611 Newbie
Currently Being Moderated

I used Private key once with SFTP sites using Oracle's Java features (I used this in PLSQL developer), as shown below, and it worked fine.

conn = new Connection(SFTP_site_IP_Address);
File keyfile = new File(RSA_Path); // where it contains the RSA key
boolean tKeyAuthentication = true;
isAuthenticated = conn.authenticateWithPublicKey(inUser_ID, keyfile, null);

Now I need to connect to a different SFTP site, but they said I need not only a private key, but also a certificate (which was provided by them)
My question is, what function to call to initiate the SFTP connection using both RSA key and digital certificate?
I did my research on Google, i found this:

InputStream key = new FileInputStream("certs/demokey.pem");
InputStream cert = new FileInputStream("certs/democert.pem"); // wrap input streams if key/cert are in pem files
key = new PEMInputStream(key);
cert = new PEMInputStream(cert);
env.setSSLClientCertificate(new InputStream[] { key, cert});

Is this the proper way to connect to SFTP using both certificate and private key?

Much appreciated,


  • Correct Answers - 10 points
  • Helpful Answers - 5 points