Two possible answers.
If you want to go the way you're going, try this to resolve the NoClassDefFoundError
.
android eclipse updated and now app crashes when it trys to run
You can also use JSch instead. I have this working reliably on android myself.
RSA Encryption forceclosing before generating public/private keys
Edit: Here's an example of using JSch to generate RSA-type keypairs. I think it's PKCS#1, but I'm not familiar enough with the standard. The relevant javadoc is what I'm going off of.
/**
* Load or generate a RSA keypair to use as a client for the given JSch.
*/
public boolean registerKeyPair(JSch jSch) {
new File(getRootFolder().getAbsolutePath() + "/.ssh").mkdirs();
File privateKey = new File(getRootFolder().getAbsolutePath() + "/.ssh/id_rsa");
File publicKey = new File(getRootFolder().getAbsolutePath() + "/.ssh/id_rsa.pub");
if (!privateKey.exists() || !publicKey.exists()) {
try {
KeyPair keyPair = KeyPair.genKeyPair(jSch, KeyPair.RSA);
keyPair.writePrivateKey(privateKey.getAbsolutePath());
keyPair.writePublicKey(publicKey.getAbsolutePath(), "Machine Shop");
return true;
} catch (JSchException e) {
Log.e("genKeyPair(RSA)", Log.getStackTraceString(e));
} catch (FileNotFoundException e) {
Log.e("genKeyPair(RSA)", Log.getStackTraceString(e));
} catch (IOException e) {
Log.e("genKeyPair(RSA)", Log.getStackTraceString(e));
}
return false;
}
try {
jSch.addIdentity(privateKey.getAbsolutePath());
return true;
} catch (JSchException e) {
Log.w("jSch.addIdentity", Log.getStackTraceString(e));
return false;
}
}
Edit: Assuming Eclipse. Include the JSch jar file in your build path, preferably as a local jar (say in a lib folder). Make sure to check it on the "Order and Export" tab.
Now refresh your project.