我想存储在我的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]!一旦我得到了这个节点,我将把它放到$节点中所有节点的循环中。