通过散列Java Mail API的密码 [英] Pass hashed password to Java Mail API

查看:83
本文介绍了通过散列Java Mail API的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



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



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

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

属性属性= new Properties();
properties.put(mail.imap.host,myserver.com);
properties.put(mail.imap.user,developmentper@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.getDefaultInstance(属性,新的Authenticator(){
@Override
protected PasswordAuthentication getPasswordAuthentication(){
返回新的PasswordAuthentication(developmentper@myserver.com mypassword);
}
});
店铺;
try {
store = session.getStore(imap);
store.connect();
文件夹文件夹= store.getFolder(Inbox);
numberOfUnreadMails = folder.getUnreadMessageCount();
} catch(Exception e){
e.printStackTrace();
}
return numberOfUnreadMails;
}

我还可以使用另一个散列算法。
如果您知道我的问题的解决方案,请事先提醒您。



PS:抱歉我的英文不好,我是法国人。

解决方案

您的IMAP服务器将需要unhashed密码才能进行身份验证。您可能已经在使用SSL(因为您设置了 mail.imap.socketFactory.class ),所以您的密码永远不会发送到明确的。



BTW:使用带有javamail的SSL的IMAP的正确方法是使用 imaps 协议(并使用邮件)。 imaps。* ,不使用imap协议并指定一个SSL套接字工厂作为套接字工厂。通常,带有SSL端口的IMAP也是993,而不是143。


Good morning everybody,

I'm developping an ERP for my company with the GWT Framework and I would get the number of unread emails using the Java Mail API. I can do this but, the problem is I stores the SHA-512 hashed password on the database and I would not pass the clear password to the Java Mail API, but just the hashed password to avoiding to transmit the clear password on the network.

I use this code to get the number of unread mail:

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

I can also use another hashing algorithm. If you know a solution for my problem, thaks you in advance.

P.S.: Sorry for my poor English, I’m French.

解决方案

Your IMAP-server will need the unhashed password to be able to authenticate. You probably are already using SSL (as you set mail.imap.socketFactory.class), so your password is never sent in the clear.

BTW: the correct way to use IMAP with SSL with javamail is to use the imaps protocol (and use the mail.imaps.*, not using the imap protocol and specifying an SSL socket factory as the socket factory. Also usually the IMAP with SSL port is 993, not 143 .

这篇关于通过散列Java Mail API的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆