示例#1
0
 /**
  * @param  string   $password
  * @param  string   $nonce
  * @return string[]
  */
 public static function generateKeys($password, $nonce)
 {
     $array = ["key", "key", "key", "key"];
     $array2 = [1, 2, 3, 4];
     $nonce .= '0';
     $count = count($array);
     for ($j = 0; $j < $count; $j++) {
         $nonce[strlen($nonce) - 1] = chr($array2[$j]);
         $foo = ProtocolService::pbkdf2("sha1", $password, $nonce, 2, 20, true);
         $array[$j] = $foo;
     }
     return $array;
 }
示例#2
0
 protected function createAuthBlob()
 {
     if ($this->challengeData) {
         $key = ProtocolService::pbkdf2('sha1', base64_decode($this->getIdentity()->getPassword()), $this->challengeData, 16, 20, true);
         $this->getConnection()->setInputKey($this->createKeyStream($key[2], $key[3]));
         $this->getConnection()->setOutputKey($this->createKeyStream($key[0], $key[1]));
         $this->getConnection()->getNodeReader()->setKey($this->getConnection()->getInputKey());
         //$this->getConnection()->getNodeWriter()->setKey($this->getConnection()->getOutputKey());
         $phone = $this->getIdentity()->getPhone();
         $array = "" . $phone->getPhoneNumber() . $this->challengeData . time() . static::WHATSAPP_USER_AGENT . " MccMnc/" . str_pad($phone->getMcc(), 3, "0", STR_PAD_LEFT) . "001";
         $this->challengeData = null;
         return $this->getConnection()->getOutputKey()->encodeMessage($array, 0, strlen($array), 0);
     }
     return null;
 }