簡體   English   中英

將哈希密碼傳遞給Java Mail API

[英]Pass hashed password to Java Mail API

大家早上好,

我正在使用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;
}

我也可以使用另一種哈希算法。 如果你知道我的問題的解決方案,請提前告訴你。

PS:對不起,我的英語很差,我是法國人。

您的IMAP服務器將需要未散列的密碼才能進行身份驗證。 您可能已經在使用SSL(因為您設置了mail.imap.socketFactory.class ),因此您的密碼永遠不會以明文形式發送。

BTW:使用帶有SSL的IMAP IMAP的正確方法是使用imaps協議(並使用mail.imaps.* ,不使用imap協議並指定SSL套接字工廠作為套接字工廠。通常使用SSL的IMAP港口是993,而不是143。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM