djangosnippets.org: Latest snippets tagged with 'encryption'https://djangosnippets.org/tags/encryption/2015-10-26T06:21:22.481135-05:00Django EncryptedField
2015-10-26T06:21:22.481135-05:00zarglexhttps://djangosnippets.org/snippets/10537/<p>Inspired by <a href="https://djangosnippets.org/snippets/1669/">Base64Field: base64 encoding field for storing binary data in Django TextFields</a> but in a generic way.</p>
<pre><code>from django.db import models
import base64
class Base64Encryptor(object):
def encrypt(self, value):
return base64.encodestring(value)
def decrypt(self, msg):
return base64.decodestring(msg)
class MyModel(models.Model):
...
b64_data = EncryptedField(encryptor=Base64Encryptor)
...
# Usage
my_obj = MyModel()
my_obj.b64_data = …</code></pre>
Freely redistributableTransparently encrypt ORM fields using OpenSSL (via M2Crypto)
2011-07-15T01:41:49.427471-05:00ncoghlanhttps://djangosnippets.org/snippets/2489/<p>Sometimes you need to store information that the server needs in unencrypted form (e.g. OAuth keys and secrets), but you don't really want to leave it lying around in the open on your server. This snippet lets you split that information into two parts:</p>
<ul>
<li>
<p>a securing passphrase, stored in the …</p></li></ul>
Freely redistributableS/MIME Encrypted E-mail
2009-07-30T09:17:06.049126-05:00bthomashttps://djangosnippets.org/snippets/1659/<p>Requires the M2Crypto module. See <a href="http://sandbox.rulemaker.net/ngps/m2/howto.smime.html">http://sandbox.rulemaker.net/ngps/m2/howto.smime.html</a> for more information on using M2Crypto to create S/MIME email. This could also be adapted to allow signing, or sign+encrypt, but currently only encrypts.</p>
<p>Use just like <code>EmailMessage</code>, except takes an extra parameter <code>cert</code>, which is the path to the recipient's public …</p>
Freely redistributableEncryption Fields
2008-09-29T17:41:51.447153-05:00zbyte64https://djangosnippets.org/snippets/1095/<p>This provides some basic cryptographic fields using pyCrypto. All encryption/decription is done transparently and defaults to use AES. Example usage:</p>
<pre><code>class DefferredJunk(models.Model):
semi_secret = EncryptedCharField(max_length=255)
</code></pre>
Freely redistributableTransparent encryption for model fields
2008-06-26T15:52:45.721256-05:00shadfchttps://djangosnippets.org/snippets/824/<p>Here's a simple way to transparently encrypt a field (just repeat the idiom for more than one) so that it is not stored plaintext in the database. This might be useful for social security numbers, etc.</p>
<p>The storage size for the ciphertext depends on which algorithm you use. Blowfish here …</p>
Freely redistributable