Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple ciphers #60

Open
michaelirey opened this issue Jul 25, 2016 · 3 comments
Open

Multiple ciphers #60

michaelirey opened this issue Jul 25, 2016 · 3 comments

Comments

@michaelirey
Copy link

michaelirey commented Jul 25, 2016

I apologize in advance being this may not be a feature of symmetric-encryption. But I was unsure of where else I could ask.

Our app has a need to encrypt data for different purposes and control access for decrypting. Some data should use one cipher while other data should use another cipher.

It looks like you can configure secondary ciphers, but it looks like this more for key rotation.

What is your suggestion? Use secondary ciphers, multiple symmetric-encryption instances each with their own config (I don't know if this is even possible), or some other method I am not clearly seeing?

Thanks!

@reidmorrison
Copy link
Owner

The simplest way is to add the multiple ciphers to the symmetric-encryption.yml configuration file, each with a unique version number.

Then to encrypt data with the version 3 key:

encrypted = SymmetricEncryption.cipher(3).encrypt("Hello World")
# "QEVuQwIAPiplaSyln4bywEKXYKDOqQ=="

If headers are enabled in the config file, then the usual SymmetricEncryption.decrypt will decrypt any encrypted value since the header will indicate which cipher was used for encryption purposes.

SymmetricEncryption.decrypt(encrypted)
# "Hello World"

It is also possible to store customer/client specific ciphers in a database table ( or other data source ), protected using the global cipher. This is a more powerful, yet more complex approach that requires creating an managing instances of SymmetricEncryption::Cipher. Let me know if you need more information on this approach.

@dpneumo
Copy link

dpneumo commented Aug 2, 2017

Customer/client specific ciphers is precisely what I have been contemplating but it has not been clear to me how to apply a stored cipher to a specific customer's records. From what you said above I can imagine that I should be able to use the customer_id as the key version (or perhaps use customer_id as index into a table containing the key version and cipher.) Does that seem appropriate? BTW. Do the key version numbers have to be sequential? A random key version number would add an additional layer of complexity for a hacker.

@kennethteh90
Copy link

kennethteh90 commented Mar 12, 2021

The simplest way is to add the multiple ciphers to the symmetric-encryption.yml configuration file, each with a unique version number.

Then to encrypt data with the version 3 key:

encrypted = SymmetricEncryption.cipher(3).encrypt("Hello World")
# "QEVuQwIAPiplaSyln4bywEKXYKDOqQ=="

If headers are enabled in the config file, then the usual SymmetricEncryption.decrypt will decrypt any encrypted value since the header will indicate which cipher was used for encryption purposes.

SymmetricEncryption.decrypt(encrypted)
# "Hello World"

It is also possible to store customer/client specific ciphers in a database table ( or other data source ), protected using the global cipher. This is a more powerful, yet more complex approach that requires creating an managing instances of SymmetricEncryption::Cipher. Let me know if you need more information on this approach.

Hi @reidmorrison, I saw that you mentioned storing client-specific ciphers in a db table... what would be the best way for me to find out more about this approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants