Example #1
0
 /**
  * {@inheritDoc}
  */
 public function hash(Password $password)
 {
     $unicode_password_string = $this->encoding_converter->convert($password->getValue(), static::HASH_SOURCE_ENCODING);
     $crypt_hasher = $this->crypt_hasher_factory->build(static::EXPECTED_HASHER_ALGORITHM);
     $binary_hash = $crypt_hasher->update($unicode_password_string)->digest();
     return Hash::fromBinaryString($binary_hash, HashType::NT_V1);
 }
Example #2
0
 /**
  * {@inheritDoc}
  *
  * NOTE: String operations are intentionally not "Unicode-aware", as the
  * LM Hash encryption algorithm is intended to operate on raw "bytes",
  * regardless of the byte-width of the character's encoding.
  */
 public function hash(Password $password)
 {
     $string_password = substr($password->getValue(), 0, static::MAXIMUM_PASSWORD_LENGTH);
     $string_password = strtoupper($string_password);
     // Null-pad the string to the maximum length
     $string_password = str_pad($string_password, static::MAXIMUM_PASSWORD_LENGTH, static::NULL_PAD_CHARACTER);
     $halves = str_split($string_password, static::PASSWORD_SLICE_LENGTH);
     // Encrypt and concatenate each half
     $binary_hash = array_reduce($halves, function ($result, $half) {
         return $result . $this->des_encrypter->encrypt($half, static::ENCRYPT_DATA_CONSTANT, CipherMode::ECB, '');
     }, '');
     return Hash::fromBinaryString($binary_hash, HashType::LM);
 }