Alpakka SFTP with user and private key, but without password


I’m trying to read data from an SFTP server. I have a username and a private key, but no password.
Is there any way to create SftpSettings from these bits?
This didn’t work:

          .withCredentials(FtpCredentials.create(settings.user, ""))
ERROR Dying because - null
java.lang.ArrayIndexOutOfBoundsException: null


I’m not sure that case is supported:

@valdum, would you be able to provide more details (e.g. full stack trace of the java.lang.ArrayIndexOutOfBoundsException: null? I think this discussion would better be moved to a new issue.


Actually, that code seems to support the case, as it calls setIdentity with the username and the SftpIdentity. The exception occurs during the signing of the request, which seems to indicate that the key I have provided cannot be used. Is there any documentation regarding possible file format(s) acceptable for the private key? The one I have is an EC private key.

The stack trace for the exception:

java.lang.ArrayIndexOutOfBoundsException: null
	at java.lang.System.arraycopy(Native Method)
	at net.schmizz.sshj.signature.SignatureECDSA.encode(
	at net.schmizz.sshj.userauth.method.KeyedAuthMethod.putSig(
	at net.schmizz.sshj.userauth.method.AuthPublickey.sendSignedReq(
	at net.schmizz.sshj.userauth.method.AuthPublickey.handle(
	at net.schmizz.sshj.userauth.UserAuthImpl.handle(
	at net.schmizz.sshj.transport.TransportImpl.handle(
	at net.schmizz.sshj.transport.Decoder.decodeMte(
	at net.schmizz.sshj.transport.Decoder.decode(
	at net.schmizz.sshj.transport.Decoder.received(

Quick update: after upgrading to the latest version of alpakka-ftp, I am still having trouble using my PK file for SFTP access. Unfortunately, the file I was given contains only the PrivateKey part, and no PublicKey part. I can see this by dumping the contents with openssl asn1parse. The file is correctly parsed as a PEMKeyPair, but an NPEx is thrown when it tries to call a method on the null PublicKey. This happens deep inside the crypto library (JcaPEMKeyConverter.getKeyPair).

I will try to follow up with the SFTP server to see if I can get a different key file.

I did some more investigation into this issue and it appears that the libraries used in Alpakka SFTP don’t work with a 512 bit ECDSA key-pair. If you generate a key with the command:

ssh-keygen -t ecdsa -f user-ecdsa -b N -m pem

If N=256 or 384, the authentication works as expected. However, if N = 521, the authentication will fail with the error above in

Thank you for digging into it!

The library Alpakka FTP uses had a later release with some breaking changes

Please try what changes to Alpakka would be required – and if this would support the algorithm.