This module has some tricky unintended inconsistent behavior with entity_metadata_wrapper.

Conveniently when you load a entity with an encrypted field, it will give you the unencrypted
value. Likewise, when you set and save a value on that field programmatically you don't need to encrypt it first.

$my_entity = entity_load($entity_id);
$my_entity_wrapper = entity_metadata_wrapper('some_entity', $my_entity);
$value = $my_entity_wrapper->field_encrypted->value();
//yay $value is decrypted for us!
$my_entity_wrapper->field_encrypted->set("Some unencrypted string");
//new value automatically encrypted

However, if you save the wrapper at some point, the values go back to their encrypted stat:

$my_entity = entity_load($entity_id);
$my_entity_wrapper = entity_metadata_wrapper('some_entity', $my_entity);
$my_entity_wrapper->field_encrypted->set("New value");

$my_entity_wrapper->save();
//Oh noes!! We saved. The value below now is encrypted :-(
print $my_entity_wrapper->field_encrypted->value();

Comments

bennybobw’s picture

Issue summary: View changes

Fixed a little comment typo in the example

greggles’s picture

Status: Active » Postponed (maintainer needs more info)

Can you state which part of this is a bug?

To be honest, I'm not familiar with the area of code you're talking about. Do you know which part of the encryption module is responsible for this behavior? Are you using encryptfapi module?

greggles’s picture

Category: bug » support
Status: Postponed (maintainer needs more info) » Fixed

Over 2 weeks without a response. Marking as a fixed support request.

bennybobw’s picture

Status: Fixed » Closed (cannot reproduce)

My bad. I just realized this is in the encrypted_text module, not in the encryption module itself.

bennybobw’s picture

Issue summary: View changes

fixed another typo so it will make more sense