Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

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

983611Jan 11 2013
Hello,

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,

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Feb 8 2013
Added on Jan 11 2013
0 comments
728 views