Source

nx-web / scripts / pubkey_create.py

Full commit
#!/usr/bin/env python

import sys

sys.path.append('..')

from nxweb.data import dkvs
from nxweb.data.dkvs.pubkey import create

from nxweb.utils.security import rsa


dkvs.initialize(host=None, port=8098)


userid = raw_input('userid: ')
name = raw_input('key name: ')
privkey_filename = raw_input('private key `pem` file (leave empty to generate one): ')

if (len(userid) == 0):
    print "error: 'userid' must not be empty."
    sys.exit(-1)

if (len(privkey_filename) == 0):
    key = rsa.Key.generate_random_key()
else:
    with open(privkey_filename, 'r') as pk_file:
        key = rsa.Key.import_key(pk_file.read())

create(userid, name, key.key_id(), key.export_public_key())
print key.export_public_key()
print key.export_key()