Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将哈希密码传递给Java邮件API_Java_Email_Imap_Jakarta Mail - Fatal编程技术网

将哈希密码传递给Java邮件API

将哈希密码传递给Java邮件API,java,email,imap,jakarta-mail,Java,Email,Imap,Jakarta Mail,各位早上好, 我正在用GWT框架为我的公司开发一个ERP,我会 使用Java Mail API的未读电子邮件数。 我可以这样做,但问题是我将SHA-512哈希密码存储在 数据库和我不会将清除密码传递给Java Mail API,而只传递哈希密码,以避免在网络上传输清除密码 我使用此代码获取未读邮件的数量: private static int getNumberOfUnreadMails() { int numberOfUnreadMails = 0; Properties pr

各位早上好,

我正在用GWT框架为我的公司开发一个ERP,我会 使用Java Mail API的未读电子邮件数。 我可以这样做,但问题是我将SHA-512哈希密码存储在 数据库和我不会将清除密码传递给Java Mail API,而只传递哈希密码,以避免在网络上传输清除密码

我使用此代码获取未读邮件的数量:

private static int getNumberOfUnreadMails() {
   int numberOfUnreadMails = 0;

    Properties properties = new Properties();
    properties.put("mail.imap.host", "myserver.com");
    properties.put("mail.imap.user", "developper@myserver.com");
    properties.put("mail.imap.socketFactory", 143);
    properties.put("mail.imap.socketFactory.class", "java.net.ssl.SSLSocketFactory");
    properties.put("mail.imap.port", 143);
    Session session = Session.getDefaultInstance(properties, new Authenticator() {
    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("developper@myserver.com", "mypassword");
        }
    });
    Store store;
    try {
        store = session.getStore("imap");
        store.connect();
        Folder folder = store.getFolder("Inbox");
           numberOfUnreadMails = folder.getUnreadMessageCount();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return numberOfUnreadMails;
}
我还可以使用另一种哈希算法。 如果你知道我的问题的解决办法,那就提前告诉你


注:对不起,我英语不好,我是法国人。

您的IMAP服务器需要未加密的密码才能进行身份验证。您可能已经在使用SSL(当您设置
mail.imap.socketFactory.class
时),因此您的密码永远不会以明文形式发送


顺便说一句:通过javamail将IMAP与SSL一起使用的正确方法是使用
imaps
协议(并使用
mail.imaps.*
,而不是使用IMAP协议并将SSL套接字工厂指定为套接字工厂。另外,通常带有SSL端口的IMAP是993,而不是143。

只需加密流量即可(看起来你可能已经这么做了)。如果你这么做的话,密码不应该已经很清楚了。散列客户端密码实际上会使系统变得不那么安全,因为它会破坏salt的任何用途(除非在服务器上对散列进行盐析,然后重新灰化)。如果您没有使用salt,则哈希将成为以明文形式发送的新密码。谢谢您的回答。是的,我认为此解决方案可以在客户端和服务器之间使用SSL连接,但如果服务器出现问题,黑客可以获得清晰的密码。您没有看到的是,如果您可以将哈希发送到n哈希是所有意图和目的的明确密码。感谢您的回答,我将更正此问题。是否有方法在服务器上使用哈希密码(如CRAM-MD5系统)并通过JavaMail API将其发送到服务器?IMAP有多个身份验证选项(支持取决于服务器),Javamail支持各种身份验证选项(使用sasl)。我已经有一段时间没有使用Javamail了,所以我不能很容易地告诉您需要做什么才能让它正常工作。