问题
I have a camel route that looks like the next one:
from("direct:download")
.pollEnrich()
.simple("sftp://my.host:22/folder/?username=foo&fileName=${header.CamelFileName}
&privateKeyFile=src/main/resources/privateSSHKey")
.to("file://state/downloaded");
The file src/main/resources/privateSSHKey is an RSA private key. That works without a problem : JSCH (library used by Camel for the SFTP endpoint) manages to connect and download the desired file.
The previous setup is ok while developing, because I can have the file with the key locally. However, for prod, we have other system in which I will be able to get a byte array with the content of the key. For that, I am changing the route to look like this:
from("direct:download")
.pollEnrich()
.simple("sftp://my.host:22/folder/?username=foo&fileName=${header.CamelFileName}
&privateKey=" + URLEncoder.encode(new String(sshPrivateKey), "UTF-8"))
.to("file://state/downloaded");
...being sshPrivateKey the byte array. Unfortunately, I always get "auth_cancel" from JSCH, and debugging I can see that this happens when trying to handshake with the SFTP server.
Am I missing something? I am pretty sure that encoding the sshPrivateKey byte[] is the way to go (JSCH was complaining about wrong key if I didn't do it), but I am not sure about what else I am missing?
来源:https://stackoverflow.com/questions/57495686/camel-sftp-component-ssh-private-key-uri-works-with-privatekeyfile-doesnt-wo