Created
January 11, 2026 08:28
-
-
Save acidsound/9f8adfba61288dbd49928faf2a103efe to your computer and use it in GitHub Desktop.
API_Key_gen.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import secrets | |
| import string | |
| import hashlib | |
| import time | |
| def generate_api_key(prefix="sk-"): | |
| """안전한 32자 API 키 생성 (OpenAI 스타일)""" | |
| # 랜덤 문자열 (대소문자 + 숫자 + 일부 특수문자) | |
| chars = string.ascii_letters + string.digits + "-_" | |
| random_part = ''.join(secrets.choice(chars) for _ in range(28)) | |
| # 타임스탬프 해시로 유니크 보장 | |
| timestamp = str(int(time.time())) | |
| hash_part = hashlib.sha256((timestamp + random_part).encode()).hexdigest()[:4] | |
| api_key = f"{prefix}{random_part}{hash_part}" | |
| return api_key | |
| def generate_multiple_keys(count=5): | |
| """여러 키 한 번에 생성""" | |
| keys = [generate_api_key() for _ in range(count)] | |
| print(f"생성된 API 키 ({count}개):\n") | |
| for i, key in enumerate(keys, 1): | |
| print(f"키 {i}: {key}") | |
| print("\napp.py의 API_KEYS = [...] 에 넣으세요!") | |
| if __name__ == "__main__": | |
| import sys | |
| if len(sys.argv) > 1 and sys.argv[1] == "--multiple": | |
| generate_multiple_keys(5) | |
| else: | |
| single_key = generate_api_key() | |
| print(f"당신의 API 키: {single_key}") | |
| print("\n복사해서 app.py에 사용하세요!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment