How can you store a rsa key pair in a django model / sqlite db -


i using pycrypto within django (python 2.7, django 1.5m sqlite), create field store rsakey object. how can this? converting string , seems pretty error prone , since random bytes in there, not trust approach. able store random keys in charfield base-64 encoding (like this: random.new().read(16).encode('base64')). keypair? saw in current dev version of django, binary field incorporated, need stick 1.5.

any appreciated.

thanks gerd

you need store private key, because can generate public key private one.

>>> crypto.publickey import rsa >>> rsakey = rsa.generate(1024) 

the public key can exported with

>>> rsakey.publickey().exportkey() 

to save private key might want convert text exportkey() method , store in django-textfield:

>>> rsakey.exportkey() '-----begin rsa private key-----\nmi...-----end' 

converting text rsa key object easy too:

>>> rsa.importkey('-----begin rsa private key--- ....') 

gets rsaobj 1 generated @ first.

you might try "hard way" creating own model field class, if intend use functionality in other areas well. see https://docs.djangoproject.com/en/1.5/howto/custom-model-fields/


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -