How to encrypt the user/pw and ftp connection in spring boot?

Viewed 237

So I have a working ftp connection and I can upload files and whatnot. However currently I'm storing the pw/user as hardcoded values (which I know isn't good) and want to see if I can hide/encrypt them somehow. I would also like to encrypt the actual ftp connection if possible as well. Any information/pointers would be great!

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;
}
2 Answers

If you are already using Spring, you could can add org.springframework.boot:spring-boot-starter-security dependency and use BCryptPasswordEncoder to encode the values:

BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
String enc = encoder.encode(value);

Documentation is here:

And this is a very helpful tutorial:

Related