gitscope
https://dev.kronoz.win/r/marzneshin.git
app/utils/keygen.py · v0.6.1
Source
1 24112b4 Dawsh 2y ago import base64
2 a47eb4c Dawsh 2y ago import uuid
3 24112b4 Dawsh 2y ago
4 24112b4 Dawsh 2y ago import xxhash
5 24112b4 Dawsh 2y ago from nacl.public import PrivateKey
6 24112b4 Dawsh 2y ago
7 f2ddb05 m0x61h0x64i 2y ago from app.config.env import AuthAlgorithm, AUTH_GENERATION_ALGORITHM
8 a47eb4c Dawsh 2y ago
9 01cdf2e Dawsh 2y ago
10 a47eb4c Dawsh 2y ago def gen_uuid(key: str) -> str:
11 f2ddb05 m0x61h0x64i 2y ago if AUTH_GENERATION_ALGORITHM == AuthAlgorithm.PLAIN:
12 f2ddb05 m0x61h0x64i 2y ago return str(uuid.UUID(key))
13 f2ddb05 m0x61h0x64i 2y ago else:
14 f2ddb05 m0x61h0x64i 2y ago return str(uuid.UUID(bytes=xxhash.xxh128(key.encode()).digest()))
15 a47eb4c Dawsh 2y ago
16 01cdf2e Dawsh 2y ago
17 a47eb4c Dawsh 2y ago def gen_password(key: str) -> str:
18 f2ddb05 m0x61h0x64i 2y ago if AUTH_GENERATION_ALGORITHM == AuthAlgorithm.PLAIN:
19 f2ddb05 m0x61h0x64i 2y ago return key
20 f2ddb05 m0x61h0x64i 2y ago else:
21 f2ddb05 m0x61h0x64i 2y ago return xxhash.xxh128(key.encode()).hexdigest()
22 24112b4 Dawsh 2y ago
23 24112b4 Dawsh 2y ago
24 24112b4 Dawsh 2y ago def generate_curve25519_pbk(key: str) -> str:
25 24112b4 Dawsh 2y ago return base64.b64encode(PrivateKey(key.encode()).encode()).decode()