Hi Simon, the integration test[1] we have, loads[2] the privateKey from file[3] and places it in the registry as byte[]. The file is in PKCS#1 PEM format unencrypted. So we know that works, there might be other formats that will work. I suggest trying with a key in PKCS#1 PEM unencrypted format and seeing if that works on your end also.
zoran [1] https://github.com/apache/camel/blob/main/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpKeyConsumeIT.java [2] https://github.com/apache/camel/blob/main/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/sftp/integration/SftpKeyConsumeIT.java#L54-L58 [3] https://github.com/apache/camel/blob/main/components/camel-ftp/src/test/resources/id_rsa On Wed, Jul 14, 2021 at 6:40 PM Simon Loy <simon....@uktv.co.uk> wrote: > > Hi All, > > Hope you are all well! > > I’m currently working on an task that involves sending files to a sftp server > but instead of using credentials I am required to use an ssh private key for > authentication. > > I have already proven that connection with the private key is successful via > command line : > > sftp -i <path_to_private_key> username@hostname > > …so I know that there is no issue with the privateKey itself! > > We store the public key in AWS Secrets manager and this is injected into our > application via Spring Cloud’s AWS Secrets Manager config starter. This is > injected into SpringBoot’s application.properties. I’ve added debug logging > to ensure there is no issue with the injecting. That value then gets stored > as an exchangeProperty and converted into a Byte Array and pass it to the > sftp command: > > .to(“sftp://{{sftp.hostname}}:{{sftp.port}}/{{sftp.root.folder}}{{sftp.infolder}}?username={{sftp.username}}&privateKey=${exchangeProperty.sshPrivateKey}”) > > When we trigger this route and the above line is executed we get the > following error: > > org.apache.camel.component.file.GenericFileOperationFailedException: Cannot > connect to sftp://gbt...@glue.brickftp.com:22 > … > Caused by: com.jcraft.jsch.JSchException: invalid privatekey > > After a bit of investigation I came across this StackOverflow > article<https://stackoverflow.com/questions/67937961/apache-camel-sftp-jschexception-invalid-privatekey-b7c033a39-with-openssh> > and noted that put private key was an openssh key so took the user Matthias > Wiedemann’s advice and switch JSCH library and attempted to connect again but > with similar failure. > > Was hoping that someone may have experienced something similar before and may > be able to help out. > > Kind Regards > Simon > Simon Loy > Solutions Developer > > simon....@uktv.co.uk > > > > [https://s3-eu-west-1.amazonaws.com/uktv/UKTVeMailSig.jpeg] > <http://www.uktv.co.uk/> -- Zoran Regvart