Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Crammd5.php
Go to the documentation of this file.
1 <?php
27 #require_once 'Zend/Mail/Protocol/Smtp.php';
28 
29 
40 {
49  public function __construct($host = '127.0.0.1', $port = null, $config = null)
50  {
51  if (is_array($config)) {
52  if (isset($config['username'])) {
53  $this->_username = $config['username'];
54  }
55  if (isset($config['password'])) {
56  $this->_password = $config['password'];
57  }
58  }
59 
60  parent::__construct($host, $port, $config);
61  }
62 
63 
69  public function auth()
70  {
71  // Ensure AUTH has not already been initiated.
72  parent::auth();
73 
74  $this->_send('AUTH CRAM-MD5');
75  $challenge = $this->_expect(334);
76  $challenge = base64_decode($challenge);
77  $digest = $this->_hmacMd5($this->_password, $challenge);
78  $this->_send(base64_encode($this->_username . ' ' . $digest));
79  $this->_expect(235);
80  $this->_auth = true;
81  }
82 
83 
92  protected function _hmacMd5($key, $data, $block = 64)
93  {
94  if (strlen($key) > 64) {
95  $key = pack('H32', md5($key));
96  } elseif (strlen($key) < 64) {
97  $key = str_pad($key, $block, "\0");
98  }
99 
100  $k_ipad = substr($key, 0, 64) ^ str_repeat(chr(0x36), 64);
101  $k_opad = substr($key, 0, 64) ^ str_repeat(chr(0x5C), 64);
102 
103  $inner = pack('H32', md5($k_ipad . $data));
104  $digest = md5($k_opad . $inner);
105 
106  return $digest;
107  }
108 }
_expect($code, $timeout=null)
Definition: Abstract.php:402
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$config
Definition: fraud_order.php:17
_hmacMd5($key, $data, $block=64)
Definition: Crammd5.php:92
$block
Definition: block.php:8
__construct($host='127.0.0.1', $port=null, $config=null)
Definition: Crammd5.php:49