Add a command for creating rsa key.
This commit is contained in:
parent
6ce523edaa
commit
9eb5f67a95
1 changed files with 18 additions and 0 deletions
18
oidc_provider/management/commands/creatersakey.py
Normal file
18
oidc_provider/management/commands/creatersakey.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from Crypto.PublicKey import RSA
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
|
||||
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)
|
Loading…
Reference in a new issue