I'm fairly new to Android development and am trying to use Jsch using a private key to access a remote server. I have placed the private key in res/raw folder but am struggling on how to access the file path of the private key when trying to authenticate. I have previously got this working for a Java project. Here is a copy of what I have so far.
private Session sshConnect() throws JSchException, IOException
{
try
{
//Login details
jschSession = jsch.getSession(sshUsername, sshServer, 22);
//Connect using private key and corresponding passphrase
jsch.addIdentity("./res/raw/id_rsa", passphrase);
//Ignore SSH key warnings
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
jschSession.setConfig(config);
//System.out.println(localPort);
jschSession.connect();
return jschSession;
}
catch (Exception ex)
{
throw new RuntimeException("SSH connection failed: " + ex.getMessage(), ex);
}
}
This then throws the following error when I try to run
java.lang.RuntimeException: SSH connection failed: java.io.FileNotFoundException: ./res/raw/id_rsa: open failed: ENOENT (No such file or directory)
I've tried the following to try and access the contents of the res folder, with no such luck:
jsch.addIdentity("file:///android_res/raw/id_rsa", passphrase);