In the User model, you can override the installer. If you want to encrypt and decrypt the user ID (using attr_encrypted) ...
You can try something like this:
attr_encrypted :id, key: ENCRYPTION_KEYS[:value] def id=(value) send("encrypted_value=", encrypt(:id, value)) instance_variable_set(:@id, value) end
Then you can create a method that decrypts the identifier
def decrypted_id decrypt(:id, encrypted_value) end
Now that the user is created, the database will set the identifier as usual. But it will also create an encrypted value that stores the identifier as an encrypted identifier. You can use this encrypted value for your application to keep the database secret code in the interface.
Here is an example in the console ...

Eric
source share