Skip to content

Commit

Permalink
Add Passphrase Normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
sugeng-sulistiyawan committed May 5, 2023
1 parent 7ac2766 commit af69d0b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/traits/EncrypterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function setEncrypter($passphrase, $iv, $cipherAlgo = 'aes-128-cbc')
throw new InvalidConfigException('The "iv" property must be set.');
}

$this->normalizePassphrase();
$this->normalizeIv();
}

Expand Down Expand Up @@ -82,9 +83,20 @@ public function decrypt($string)
return $decodedString;
}

/**
* @param int $minPassphraseLength
* @return void
*/
private function normalizePassphrase($minPassphraseLength = 32)
{
$passphraseLength = strlen($this->_passphrase);
if ($passphraseLength < $minPassphraseLength) {
$this->_passphrase = str_repeat($this->_passphrase, (int) ceil($minPassphraseLength / $passphraseLength));
}
}

/**
* @return void
* @throws InvalidConfigException
*/
private function normalizeIv()
{
Expand Down

0 comments on commit af69d0b

Please sign in to comment.