diff --git a/src/Appwrite/Migration/Version/V06.php b/src/Appwrite/Migration/Version/V06.php index f533135446..715508f787 100644 --- a/src/Appwrite/Migration/Version/V06.php +++ b/src/Appwrite/Migration/Version/V06.php @@ -2,11 +2,13 @@ namespace Appwrite\Migration\Version; +use Utopia\App; use Utopia\CLI\Console; use Utopia\Config\Config; use Appwrite\Database\Database; use Appwrite\Database\Document; use Appwrite\Migration\Migration; +use Appwrite\OpenSSL\OpenSSL; class V06 extends Migration { @@ -22,6 +24,8 @@ class V06 extends Migration { switch ($document->getAttribute('$collection')) { case Database::SYSTEM_COLLECTION_USERS: + var_dump($this->applyFilterEncrypt($document->getAttribute("email"))); + if ($document->getAttribute('password-update', null)) { $document ->setAttribute('passwordUpdate', $document->getAttribute('password-update', $document->getAttribute('passwordUpdate', ''))) @@ -53,4 +57,19 @@ class V06 extends Migration } return $document; } + + private function applyFilterEncrypt(String $value) + { + $key = App::getEnv('_APP_OPENSSL_KEY_V1'); + $iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM)); + $tag = null; + + return json_encode([ + 'data' => OpenSSL::encrypt($value, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag), + 'method' => OpenSSL::CIPHER_AES_128_GCM, + 'iv' => bin2hex($iv), + 'tag' => bin2hex($tag), + 'version' => '1', + ]); + } }