41 public function crypt( $password ) {
42 $secret = $this->config[
'secrets'][$this->params[
'secret']];
45 while ( openssl_error_string() !==
false );
48 $decrypted = openssl_decrypt(
49 $this->hash, $this->params[
'cipher'],
50 $secret, 0, base64_decode( $this->args[0] ) );
51 if ( $decrypted ===
false ) {
52 throw new PasswordError(
'Error decrypting password: ' . openssl_error_string() );
54 $underlyingPassword = $this->factory->newFromCiphertext( $decrypted );
56 $underlyingPassword = $this->factory->newFromType( $this->config[
'underlying'] );
59 $underlyingPassword->crypt( $password );
60 if ( count( $this->args ) ) {
61 $iv = base64_decode( $this->args[0] );
66 $this->hash = openssl_encrypt(
67 $underlyingPassword->toString(), $this->params[
'cipher'], $secret, 0, $iv );
68 if ( $this->hash ===
false ) {
69 throw new PasswordError(
'Error encrypting password: ' . openssl_error_string() );
71 $this->args = [ base64_encode( $iv ) ];
81 if ( count( $this->args ) != 1 || $this->params == $this->
getDefaultParams() ) {
87 while ( openssl_error_string() !==
false );
90 $underlyingHash = openssl_decrypt(
92 $this->params[
'cipher'],
93 $this->config[
'secrets'][$this->params[
'secret']],
95 base64_decode( $this->args[0] )
97 if ( $underlyingHash ===
false ) {
98 throw new PasswordError(
'Error decrypting password: ' . openssl_error_string() );
106 $this->hash = openssl_encrypt(
108 $this->params[
'cipher'],
109 $this->config[
'secrets'][$this->params[
'secret']],
113 if ( $this->hash ===
false ) {
114 throw new PasswordError(
'Error encrypting password: ' . openssl_error_string() );
117 $this->args = [ base64_encode( $iv ) ];