mirror of
https://github.com/yuaotian/go-cursor-help.git
synced 2025-06-08 12:32:06 +08:00
Enhance ID generation in macOS and Windows scripts
- Added a function to generate random hexadecimal strings in the Windows ID modifier script for improved randomness. - Updated the macOS script to concatenate a hexadecimal representation of the prefix "auth0|user_" with a random ID, ensuring a consistent format for machine IDs across platforms. - Improved comments in both scripts for better clarity on the ID generation process.
This commit is contained in:
parent
d0415ff710
commit
9495ba7f71
@ -128,6 +128,7 @@ backup_config() {
|
||||
|
||||
# 生成随机 ID
|
||||
generate_random_id() {
|
||||
# 生成32字节(64个十六进制字符)的随机数
|
||||
openssl rand -hex 32
|
||||
}
|
||||
|
||||
@ -138,7 +139,13 @@ generate_uuid() {
|
||||
|
||||
# 生成新的配置
|
||||
generate_new_config() {
|
||||
local machine_id="auth0|user_$(generate_random_id)"
|
||||
# 将 auth0|user_ 转换为字节数组的十六进制
|
||||
local prefix_hex=$(echo -n "auth0|user_" | xxd -p)
|
||||
# 生成随机部分
|
||||
local random_part=$(generate_random_id)
|
||||
# 拼接前缀的十六进制和随机部分
|
||||
local machine_id="${prefix_hex}${random_part}"
|
||||
|
||||
local mac_machine_id=$(generate_random_id)
|
||||
local device_id=$(generate_uuid | tr '[:upper:]' '[:lower:]')
|
||||
local sqm_id="{$(generate_uuid | tr '[:lower:]' '[:upper:]')}"
|
||||
|
@ -110,9 +110,26 @@ if (Test-Path $STORAGE_FILE) {
|
||||
# 生成新的 ID
|
||||
Write-Host "$GREEN[信息]$NC 正在生成新的 ID..."
|
||||
|
||||
# 生成随机字节数组并转换为十六进制字符串的函数
|
||||
function Get-RandomHex {
|
||||
param (
|
||||
[int]$length
|
||||
)
|
||||
$bytes = New-Object byte[] $length
|
||||
$rng = [System.Security.Cryptography.RNGCryptoServiceProvider]::new()
|
||||
$rng.GetBytes($bytes)
|
||||
$rng.Dispose()
|
||||
return -join ($bytes | ForEach-Object { '{0:x2}' -f $_ })
|
||||
}
|
||||
|
||||
$UUID = [System.Guid]::NewGuid().ToString()
|
||||
$MACHINE_ID = -join ((1..32) | ForEach-Object { '{0:x2}' -f (Get-Random -Max 256) })
|
||||
$MAC_MACHINE_ID = -join ((1..32) | ForEach-Object { '{0:x2}' -f (Get-Random -Max 256) })
|
||||
# 将 auth0|user_ 转换为字节数组的十六进制
|
||||
$prefixBytes = [System.Text.Encoding]::UTF8.GetBytes("auth0|user_")
|
||||
$prefixHex = -join ($prefixBytes | ForEach-Object { '{0:x2}' -f $_ })
|
||||
# 生成32字节(64个十六进制字符)的随机数作为 machineId 的随机部分
|
||||
$randomPart = Get-RandomHex -length 32
|
||||
$MACHINE_ID = "$prefixHex$randomPart"
|
||||
$MAC_MACHINE_ID = Get-RandomHex -length 32
|
||||
$SQM_ID = "{$([System.Guid]::NewGuid().ToString().ToUpper())}"
|
||||
|
||||
# 创建或更新配置文件
|
||||
|
Loading…
x
Reference in New Issue
Block a user