【问题标题】:How can I generate a correct CRAM-MD5 response in PHP?如何在 PHP 中生成正确的 CRAM-MD5 响应?
【发布时间】:2021-06-08 02:54:33
【问题描述】:

我希望为 SMTP 服务器生成 CRAM-MD5 响应。

我可以在这里看到如何做到这一点的理论细节:CRAM-MD5 Implementation,但我正在寻找特定的 PHP 代码以实现它。

如何在 PHP 中实现这个?

【问题讨论】:

    标签: php smtp md5


    【解决方案1】:

    以下 PHP 代码将为 CRAM-MD5 生成有效响应:

    $username = "username goes here";
    $password = "password goes here";
    
    $challenge = "challenge from server goes here";
    
    $challenge = base64_decode($challenge);
    $digest = hash_hmac("md5", $challenge, $password, false);
    var_dump(base64_encode($username . ' ' . $digest));
    

    在 telnet 会话中,您可以这样使用它:

    telnet your.smtp.server.com 25
    Trying 123.123.123.123...
    Connected to your.smtp.server.com.
    Escape character is '^]'.
    220 your.smtp.server.com
    EHLO your.server.com
    ...
    250-AUTH PLAIN LOGIN DIGEST-MD5 CRAM-MD5
    ...
    AUTH CRAM-MD5
    334 <challenge from server>
    <output from var_dump goes here>
    235 2.7.0 Authentication successful
    

    【讨论】:

      猜你喜欢
      • 2011-10-09
      • 1970-01-01
      • 2011-01-05
      • 1970-01-01
      • 2020-06-20
      • 2017-06-12
      • 2011-01-29
      • 1970-01-01
      • 2012-11-02
      相关资源
      最近更新 更多