Recently PHP7.2 was released with the Sodium library included for encryption.
Of course there were already encryption modules available, even working with Zend Framework 2 or Symfony. We were in need of an implementation for Zend Framework 3 and not wanting to rely on our own encryption method ideas, we created a ZF3 & Doctrine 2 module that uses paragonie's encryption implementation.
The purpose, at the moment, is to be able to automatically encrypt and decrypt on read/write of certain properties, detected via a listener hooked into the Doctrine ORM.
How we've set it up is the following:
Default
- Receive a string (do not encrypt
null
) - Add in-code (config) salt to string
- Use in-code (config) private key for encryption
Obviously, not the strongest method of extending a string, but this is to make sure we can encrypt data marked with a tag using default settings. Data such as a street name.
Options
- Receive a string (do not encrypt
null
) - Add generated 32 char salt and/or pepper before (and after) string (stored in separate db table, though records linked via foreign key)
- Add in-code (config) salt to string
- Use in-code (config) private key for encryption
This is the module we, actually just me, created. The actual implementation of the encryption/decryption starts about here.
processFields
function - decides whether to encrypt/decrypt, passes values and, on decrypt, tries a type cast (to support value types) to return original value typeencrypt
function - decides if salt and/or pepper need to be added based upon passed options. Then calls "encrypt
" on adapter.decrypt
function - decides if salt and/or pepper were added based upon passed options. Removes them from string to return original string to encrypt.- Halite adapter - This is the default encryption/decryption adapter
Why am I asking?
Because I hope I've understood most everything right and thus created something awesome. However, as I'm not cryptology expert and we have no such person in-house, I thought to ask here, hoping to gain some feedback.
The code is provided as is and open source. It's extendable and re-usable so others can use the same service but can use their own encryption adapter. However, I wouldn't want them using something sub-par.