I'm trying to get an ssh private key data from command line.
./myProgram --prvKey '-----BEGIN RSA PRIVATE KEY-----\nxxx\n-----END RSA PRIVATE KEY-----\n'
In my Git class, I use the key data as below:
protected JSch createDefaultJSch(FS fs) throws JSchException {
String prvKeyData = Main.getPrvKeyData();
System.out.println(prvKeyData);
JSch jSch = super.createDefaultJSch(fs);
jSch.addIdentity("monitoring-configs", prvKeyData.getBytes(), null, "passphrase".getBytes());
return jSch;
}
But this fails with an invalid ssh key error message.
I checked that it works well when putting that string into the code directly.
And I also checked that the System.out.println
result is exactly the same as the input I gave(containing \n
).
I guess that bash does something with backslashes, so that in my Java program, the \n
is not understood properly.
How can I debug and resolve this?