-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_key.py
More file actions
56 lines (46 loc) · 1.6 KB
/
debug_key.py
File metadata and controls
56 lines (46 loc) · 1.6 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
#!/usr/bin/env python3
"""
Debug script to test Fernet key handling
"""
import os
from dotenv import load_dotenv
from cryptography.fernet import Fernet
# Load environment variables
load_dotenv()
print("🔍 Debugging Fernet Key Issue")
print("=" * 40)
# Get the encryption key from environment
encryption_key = os.getenv("ENCRYPTION_KEY")
print(f"Environment ENCRYPTION_KEY: {encryption_key}")
print(f"Key length: {len(encryption_key) if encryption_key else 'None'}")
print(f"Key type: {type(encryption_key)}")
if encryption_key:
print(f"Key ends with '=': {encryption_key.endswith('=')}")
print(f"Key length == 44: {len(encryption_key) == 44}")
# Test direct Fernet creation
try:
cipher = Fernet(encryption_key)
print("✅ Direct Fernet creation: SUCCESS")
except Exception as e:
print(f"❌ Direct Fernet creation: FAILED - {e}")
# Test with encoding
try:
cipher = Fernet(encryption_key.encode())
print("✅ Encoded Fernet creation: SUCCESS")
except Exception as e:
print(f"❌ Encoded Fernet creation: FAILED - {e}")
# Test generating a new key
print("\n🔑 Testing new key generation:")
new_key = Fernet.generate_key()
print(f"Generated key: {new_key}")
print(f"Generated key decoded: {new_key.decode()}")
try:
cipher = Fernet(new_key)
print("✅ Generated key works: SUCCESS")
except Exception as e:
print(f"❌ Generated key: FAILED - {e}")
try:
cipher = Fernet(new_key.decode())
print("✅ Generated key (decoded) works: SUCCESS")
except Exception as e:
print(f"❌ Generated key (decoded): FAILED - {e}")