-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate_keys.py
More file actions
executable file
·73 lines (64 loc) · 2.4 KB
/
generate_keys.py
File metadata and controls
executable file
·73 lines (64 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
"""
Utility script to generate Django secret key and encryption key for Inethi backend setup.
Run this script to get the keys needed for your .env file.
"""
import sys
from cryptography.fernet import Fernet
def generate_django_secret_key():
"""Generate a Django secret key."""
try:
from django.core.management.utils import get_random_secret_key
return get_random_secret_key()
except ImportError:
print("Warning: Django not available, generating a random key instead.")
import secrets
import string
chars = string.ascii_letters + string.digits + "!@#$%^&*(-_=+)"
return ''.join(secrets.choice(chars) for _ in range(50))
def generate_encryption_key():
"""Generate an encryption key for Fernet."""
return Fernet.generate_key().decode()
def main():
print("=" * 60)
print("🔑 Inethi Backend Key Generator")
print("=" * 60)
print()
try:
# Generate Django secret key
print("📝 Generating Django Secret Key...")
django_key = generate_django_secret_key()
print(f"✅ Django Secret Key:")
print(f" {django_key}")
print()
# Generate encryption key
print("🔐 Generating Encryption Key...")
encryption_key = generate_encryption_key()
print(f"✅ Encryption Key:")
print(f" {encryption_key}")
print()
# Display usage instructions
print("=" * 60)
print("📋 Usage Instructions:")
print("=" * 60)
print()
print("Add these keys to your .env file:")
print()
print(f"DJANGO_SECRET_KEY={django_key}")
print(f"ENCRYPTION_KEY={encryption_key}")
print()
print("⚠️ Important Security Notes:")
print(" • Keep these keys secure and never commit them to version control")
print(" • Use different keys for development and production")
print(" • Store production keys securely (e.g., environment variables)")
print()
print("🎉 Keys generated successfully!")
except Exception as e:
print(f"❌ Error generating keys: {e}")
print()
print("💡 Troubleshooting:")
print(" • Make sure you have the required packages installed:")
print(" pip install cryptography django")
sys.exit(1)
if __name__ == "__main__":
main()