Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6747193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:24:46+00:00 2026-05-26T12:24:46+00:00

Updated I have the following custom field class: class Binary(models.Field): __metaclass__ = models.SubfieldBase def

  • 0

Updated

I have the following custom field class:

class Binary(models.Field):
    __metaclass__ = models.SubfieldBase
    def get_prep_value(self, value):
       return encryptAES(key, iv_random, str(value))
    def to_python(self, value):
       return value
    def db_type(self, connection):
       return 'VARBINARY(900)'

This is the Model I have:

class Received(models.Model):
   user = models.ForeignKey(User, unique=False, editable=False)
   address = Binary(blank=True)
   aes_key = Binary(blank=True)
   iv = Binary(blank=True)      

I am trying to encrypt/decrypt data using the custom field class. When a form is submitted by the user the get_prep_value method needs to encrypt the data. In the Django Admin interface I need the to_python method to decrypt the data fields in the change view. I was thinking of making the following additions to the to_python method:

def to_python(self, value):
        return decryptAES(aes_key?, iv?, value)

The problem I’m having is that the to_python method loops through each field’s value individually, whereas I need the values of the field itself, including the fields aes_key and iv to decrypt the data. I don’t know how to get the aes_key and iv fields, hence the question marks.

Hope this clears things up.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:24:47+00:00Added an answer on May 26, 2026 at 12:24 pm

    Based on the update to your question, what you’re trying to do isn’t really feasible. If you want the field to be able to encrypt/decrypt itself automatically, then all the information required to do so must be stored in the corresponding database field (see @DanielRoseman’s answer). That essentially negates the usefulness of encryption if your database is ever compromised. Though, I guess an intruder would still have to figure out how to piece it together properly.

    There is absolutely no way to store the requisite information across multiple database fields yet have one field that pulls all the info together to decrypt itself. Fields are isolated entities. They, pretty obviously, aren’t allowed to have any information about other fields on the model because they can be used in places where those other fields might not exist on the model.

    Your best bet is to store the encrypted value and the info needed to decrypt it in standard Django model fields, and have a one model method that decrypts the value and another than encrypts the value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following classes: class Vigil < ActiveRecord::Base after_update :do_something_cool private def do_something_cool
I have the following models but I cannot get the custom method reorder_action_items to
I have the following view models: public class Search { public int Id {
I have the following code: UPDATE myTable SET Col1 = @Value However, I have
I have the following code in a custom module as well as I have
I have the following as the value for my textbox in SSRS report: =iif(IsNothing(Fields!MyDate.Value),
I have the following setup using Core Data: Nib1: A WindowController with two custom
Experts, I have JQGrid with custom template column like Edit. the following screen display
I'm writing an MVC2 app using DataAnnotations. I have a following Model: public class
I have the following in my web.config <httpErrors errorMode="Custom"> <remove statusCode="500" subStatusCode="-1" /> <error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.