Skip to content

JonasChen0103/flask-secret-key-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

隨機密鑰產生器

這個簡單的 Python 工具用於產生安全的隨機十六進制字串,可用作密鑰、權杖或唯一識別碼。

功能

  • 產生密碼學安全的隨機位元組序列
  • 將隨機位元組轉換為十六進制字串
  • 可自定義產生的密鑰長度

安裝要求

  • Python 3.6 或更高版本

使用方法

直接執行以下程式碼產生一個 32 位元組(64 個十六進制字符)的隨機字串:

import os
print(os.urandom(32).hex())

參數說明

os.urandom(32) 中的 32 表示產生的隨機位元組數。如果需要更長或更短的密鑰,可以調整這個值。

範例

import os

# 產生 16 位元組(32 個十六進制字符)的隨機字串
short_key = os.urandom(16).hex()
print(f"短密鑰: {short_key}")

# 產生 32 位元組(64 個十六進制字符)的隨機字串
standard_key = os.urandom(32).hex()
print(f"標準密鑰: {standard_key}")

# 產生 64 位元組(128 個十六進制字符)的隨機字串
long_key = os.urandom(64).hex()
print(f"長密鑰: {long_key}")

安全說明

  • os.urandom() 使用作業系統的隨機數產生器,通常是密碼學安全的
  • 產生的隨機位元組適用於加密密鑰、會話權杖等安全敏感應用
  • 在生產環境中使用時,請確保您的 Python 環境和作業系統保持最新狀態

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages