ParagonIE\PasswordLock\PasswordLock::rotateKey PHP Method

rotateKey() public static method

Key rotation method -- decrypt with your old key then re-encrypt with your new key
public static rotateKey ( string $ciphertext, Defuse\Crypto\Key $oldKey, Defuse\Crypto\Key $newKey ) : string
$ciphertext string
$oldKey Defuse\Crypto\Key
$newKey Defuse\Crypto\Key
return string
    public static function rotateKey(string $ciphertext, Key $oldKey, Key $newKey) : string
    {
        $plaintext = Crypto::decrypt($ciphertext, $oldKey);
        return Crypto::encrypt($plaintext, $newKey);
    }

Usage Example

Beispiel #1
0
 /**
  * Key rotation method -- decrypt with your old key then re-encrypt with your new key
  *
  * @param string             $hashedValue
  * @param \Defuse\Crypto\Key $newKey
  *
  * @return string
  */
 public function shouldRecreate(string $hashedValue, Key $newKey) : string
 {
     return PasswordLock::rotateKey($hashedValue, $this->key, $newKey);
 }