首页 > 解决方案 > 如何在spring boot中加密用户/密码和ftp连接?

问题描述

所以我有一个有效的 ftp 连接,我可以上传文件等等。但是目前我将 pw/user 存储为硬编码值(我知道这不好),并想看看我是否可以以某种方式隐藏/加密它们。如果可能的话,我还想加密实际的 ftp 连接。任何信息/指针都会很棒!

private int ftpProcess(String serverName, String userName, String password) {
    FTPClient ftp = new FTPClient();
    int statusCode = 0;
    try {
        ftp.connect(serverName);
        // was required to add this passive mode in TC8 to connect to the mainframe
        ftp.enterLocalPassiveMode();

        ftp.login(userName, password);

        ftp.site("filetype=jes");

        submitJcl(ftp, "submitTest.txt", serverName);

        ftp.quit();
    } catch (Exception e) {
        logger.error(e);
        statusCode = 3;
    }
    return statusCode;
}

标签: javaspring-bootencryptionftp

解决方案


您可以使用 Jasypt 加密 application.properties 中的值。

有关详细说明,请参见以下链接: https ://stackoverflow.com/a/37424296/13454816


推荐阅读