| 123456789101112131415161718192021222324252627282930313233343536373839 |
- import os
- class apikey:
- """
- This create new random API key.
- """
- def __new__(cls, lenght: int = 128) -> str:
- """
- This create new random API key.
- lenght: int - Lenght os the api key (default: 128)
- return: str - API key
- """
- byte = cls.__get_random(lenght)
- string = cls.__to_hex(byte)
- return string
- def __to_hex(byte: bytes) -> str:
- """
- This convert random bytes to string.
-
- byte: bytes - Bytes array to convert
- return: str - Result as string
- """
- return byte.hex()
- def __get_random(lenght: int) -> bytes:
- """
- Get random count of hex chars from os.
- lenght: int - Lenght of the bytes
- return: bytes - Random bytes from os
- """
- return os.urandom(lenght)
|