This repository has been archived on 2021-03-01. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
kaneton/test/packages/ktp/key.py
Mercier Pierre-Olivier fee4dd4e6d Initial snapshot
2013-02-11 22:04:30 +01:00

47 lines
1 KiB
Python

#
# ---------- header -----------------------------------------------------------
#
# project kaneton
#
# license kaneton
#
# file /home/mycure/KANETON-TEST-SYSTEM/packages/ktp/key.py
#
# created julien quintard [mon oct 25 20:11:55 2010]
# updated julien quintard [wed oct 27 13:11:59 2010]
#
#
# ---------- packages ---------------------------------------------------------
#
from OpenSSL import crypto
#
# ---------- definitions ------------------------------------------------------
#
Extension = ".key"
#
# ---------- functions --------------------------------------------------------
#
#
# this function generates a cryptographic key.
#
def Generate(type = crypto.TYPE_RSA,
length = 2048):
key = crypto.PKey()
key.generate_key(type, length)
return key
#
# this function stores a key.
#
def Store(path,
key):
open(path,
'w').write(crypto.dump_privatekey(crypto.FILETYPE_PEM, key))