-
Notifications
You must be signed in to change notification settings - Fork 51
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
Pass options to pgp_sym_encrypt #135
Comments
@SiddharthPant It's currently not configurable in this package but a PR would be welcome. |
This is also related to #89 |
What if you did something like this:
.format picks up the {}, % picks up the %s |
To implement the custom encryption options for django-pgcrypto-fields, you can modify the existing implementation by adding an optional keyword argument for the cipher algorithm when creating a CharPGPSymmetricKeyField. This will allow you to pass in the desired cipher algorithm as an option when calling pgp_sym_encrypt function. Here's how you can achieve it:
Now you can create a `CharPGPSymmetricKeyField instance with custom cipher algorithm options like this:
You may also introduce a settings.py variable to configure the default cipher algorithm. To achieve this, in the fields.py file, replace the following line:
With
Don't forget to import the settings module at the top of the fields.py file:
Now, you can set the default cipher algorithm in your project's settings.py` file:
This should provide you with customizable cipher algorithm options for the django-pgcrypto-fields package. To pass options to pgp_sym_encrypt and customize the cipher algorithm used for encryption in CharPGPSymmetricKeyField, you can modify the encrypt method of the PGPTextField class in pgcrypto_fields/fields.py. Here's an example implementation:
In this example, we've added an options parameter to the pgp_sym_encrypt method call, which allows you to customize the cipher algorithm used for encryption. We've also renamed the class to CharPGPSymmetricKeyField to avoid confusion with the existing PGPSymmetricKeyField. Alternatively, you could use a settings variable to customize the cipher algorithm option. You could define a PGCRYPTO_CIPHER_ALGO setting in your settings.py file and modify the encrypt method to use it:
In this implementation, we've defined a PGCRYPTO_CIPHER_ALGO setting in settings.py and used it to customize the cipher algorithm option in the encrypt method. This allows you to easily change the cipher algorithm used for encryption without modifying the code directly. |
@some1ataplace PRs welcome |
pgp_sym_encrypt function supports certain options. For example by default it uses AES128 algorithm to encrypt but you can customize
pgp_sym_encrypt(data, psw, 'compress-algo=1, cipher-algo=aes256')
. Is there a way I can provide the cipher-algo option with value AES256 when I createCharPGPSymmetricKeyField
or maybe in the settings file? If there is not then could there please be an enhancement that can be made for this?The text was updated successfully, but these errors were encountered: