我想存儲在我的D8數據庫加密的數據,並解密它顯示給授權用戶:Drupal的8節點 - >的setTitle
use \Defuse\Crypto\Key;
use \Defuse\Crypto\Crypto;
function my_module_node_load($nodes) {
$key = loadEncryptionKeyFromConfig();
$title = $nodes[1]->getTitle(); // $title is "def369u8765"
$decrypted_title = Crypto::decrypt($title, $key); //$decrypted_title is 'a test note'
$nodes[1]->setTitle($decrypted_title);
$nodes[1]->getTitle(); // returns 'a test note'
return $nodes;
}
當它實際上被顯示我的網頁上,它仍然是加密版本。在db中,node_field_revision仍然顯示加密版本,並且時間戳記自昨天起保持不變。
我在做什麼錯?我應該如何返回解密版本?
我不想在我的數據庫中解密它。它必須在磁盤上保持加密。編輯:我添加$節點[1] - >保存();並且它(可預測地)進入了無限循環,因爲node_load作爲save()過程的一部分被調用。
編輯:我知道我不應該硬編碼[1]!一旦我得到了這個節點,我將把它放到$節點中所有節點的循環中。