哈希密码会导致FTP上载问题

时间:2014-04-11 15:48:32

标签: java android apache-commons ftp-client ftps

我有一个Android应用程序,可以将数据上传到FTP(S)服务器。一切正常,直到我的密码哈希。奇怪的是登录/上传和断开连接到服务器似乎工作,但我的FTP没有显示新的数据。

下面是我填写密码的代码:

MessageDigest sha;
    try {
        sha = MessageDigest.getInstance("SHA-1");
        byte[] hashOne = sha.digest(etPassword.getText().toString().getBytes());
        server.setPassword(hexEncode(hashOne));
    } catch (NoSuchAlgorithmException e) {
        //
    }

static private String hexEncode(byte[] aInput) {
    StringBuffer result = new StringBuffer();
    char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
    for (byte b : aInput) {
        result.append(digits[(b & 0xf0) >> 4]);
        result.append(digits[b & 0x0f]);
    }
    return result.toString();
}

并在我的上传服务中:

private void ftpUpload(File localSrc) {
    try {
        FTPSClient ftps = new FTPSClient();
        ftps.connect(server.getIp());
        ftps.login(server.getUser(), server.getPassword());
        ftps.changeWorkingDirectory(server.getRemoteDir());
        ftps.setFileType(FTPClient.BINARY_FILE_TYPE);

        try {
            upload(localSrc, ftps); // does the upload magic
        } catch (Exception e) {
            // 
        } finally {
            ftps.disconnect();
        }
    } catch (Exception e) {
        //
    }
}

出于测试目的,我尝试使用FTPClient,但我遇到了同样的问题。

顺便说一句,我使用Apache commons-net作为FTP的东西。

我没有例外,一切似乎都运转得很好。 (ftps.isConnected()也说我有联系)。但是没有新的数据被放到FTP服务器上。有谁知道问题可能是什么?

编辑:我不确定我的帖子是否清楚。我希望用户输入FTP(S)服务器的ip /用户名/密码以及稍后在应用程序中应该将一些数据上传到此服务器。由于我不想在我的数据库中以明文保存用户密码,我想先将其哈希。但是因为我在将密码保存到数据库之前对其进行了哈希处理,因此我无法登录FTP(S)服务器,因为密码错误。

所以我的问题是:如何获得哈希密码并仍然可以使用它登录到FTP(S)服务器?

1 个答案:

答案 0 :(得分:0)

你在服务器端散列密码而不是在客户端。 您将密码发送到FTP服务器服务器哈希它并与用户数据库中的哈希进行比较。