# Encrypting serialized Attribute

**URL:** <https://www.ruby-forum.com/t/encrypting-serialized-attribute/167318>\
**Category:** Rails\
**Created:** [May 6, 2009, 5:51pm UTC](https://www.ruby-forum.com/t/encrypting-serialized-attribute/167318 "2009-05-06T17:51:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![heisam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/5f8ce5/32.png) [@heisam](https://www.ruby-forum.com/u/heisam)\
**Post date:** [May 6, 2009, 5:51pm UTC](https://www.ruby-forum.com/t/encrypting-serialized-attribute/167318/1 "2009-05-06T17:51:48Z")

</div>

Hi,

I’d like to encrypt the content of a serialized attribute with rails  
built in serialize declaration. Unfortunately, using the before\_save  
and after\_find callbacks for encryption does not work in this case,  
because they are called before serialization and after  
deserialization.

Is there a way to implement custom callbacks like after\_serialize and  
before\_deserialize or any other recommended way of implementing  
encryption of serialized attributes?

Many thanks

Sam
