django-oidc-provider/oidc_provider/management/commands/creatersakey.py

19 lines
639 B
Python
Raw Normal View History

2015-07-13 18:49:08 +00:00
from Crypto.PublicKey import RSA
from django.conf import settings
2015-10-17 21:02:37 +00:00
from django.core.management.base import BaseCommand
2015-07-13 18:49:08 +00:00
class Command(BaseCommand):
help = 'Randomly generate a new RSA key for the OpenID server'
def handle(self, *args, **options):
try:
key = RSA.generate(1024)
file_path = settings.BASE_DIR + '/OIDC_RSA_KEY.pem'
with open(file_path, 'w') as f:
f.write(key.exportKey('PEM'))
self.stdout.write('RSA key successfully created at: ' + file_path)
except Exception as e:
self.stdout.write('Something goes wrong: ' + e.message)