使用privateKey字符串的DefaultSftpSessionFactory

时间:2017-04-07 22:17:55

标签: spring-integration spring-integration-sftp

我正在寻找一种使用私钥字符串创建DefaultSftpSessionFactory的方法。其中可用的不同功能是使用私有密钥资源(本地文件)。

为SftpRemoteFileTemplate创建SessionFactory的任何想法?我有用户,主机和私钥作为字符串。

-Thanks

1 个答案:

答案 0 :(得分:1)

setter需要Resource ...

/**
 * Allows you to set a {@link Resource}, which represents the location of the
 * private key used for authenticating against the remote host. If the privateKey
 * is not provided, then the {@link DefaultSftpSessionFactory#setPassword(String) password}
 * property is mandatory (or {@link #setUserInfo(UserInfo) userInfo} that returns a
 * password.
 * @param privateKey The private key.
 * @see JSch#addIdentity(String)
 * @see JSch#addIdentity(String, String)
 */
public void setPrivateKey(Resource privateKey) {
    this.privateKey = privateKey;
}

Resource种类很多,包括ByteArrayResource,您可以使用

setPrivateKey(new ByteArrayResource(myKeyString.getBytes());