chore: 从 git 中移除 backend/target 目录
- 使用 git rm --cached 从版本控制中删除 target 目录 - .gitignore 已配置忽略 target 和 node_modules - 本地文件保留,仅从 git 索引中删除 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
934b8aad40
commit
ea8f8390da
99 files changed
+3551
-724
No files matched your search
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* 密码加密工具
|
||||
* 使用 Web Crypto API 进行 SHA-256 哈希
|
||||
*/
|
||||
|
||||
/**
|
||||
* 将字符串转换为 ArrayBuffer
|
||||
*/
|
||||
function stringToArrayBuffer(str: string): ArrayBuffer {
|
||||
const encoder = new TextEncoder()
|
||||
return encoder.encode(str).buffer
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 ArrayBuffer 转换为十六进制字符串
|
||||
*/
|
||||
function arrayBufferToHex(buffer: ArrayBuffer): string {
|
||||
const bytes = new Uint8Array(buffer)
|
||||
return Array.from(bytes)
|
||||
.map(b => b.toString(16).padStart(2, '0'))
|
||||
.join('')
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用 SHA-256 算法哈希密码
|
||||
* @param password 明文密码
|
||||
* @returns 哈希后的十六进制字符串
|
||||
*/
|
||||
export async function hashPassword(password: string): Promise<string> {
|
||||
if (!password) return ''
|
||||
|
||||
try {
|
||||
// 使用 Web Crypto API 进行 SHA-256 哈希
|
||||
const data = stringToArrayBuffer(password)
|
||||
const hashBuffer = await crypto.subtle.digest('SHA-256', data)
|
||||
return arrayBufferToHex(hashBuffer)
|
||||
} catch (error) {
|
||||
console.error('密码哈希失败:', error)
|
||||
throw new Error('密码加密失败')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 简单的加盐哈希(可选,用于增强安全性)
|
||||
* @param password 明文密码
|
||||
* @param salt 盐值
|
||||
* @returns 哈希后的十六进制字符串
|
||||
*/
|
||||
export async function hashPasswordWithSalt(password: string, salt: string): Promise<string> {
|
||||
if (!password) return ''
|
||||
|
||||
try {
|
||||
const saltedPassword = password + salt
|
||||
const data = stringToArrayBuffer(saltedPassword)
|
||||
const hashBuffer = await crypto.subtle.digest('SHA-256', data)
|
||||
return arrayBufferToHex(hashBuffer)
|
||||
} catch (error) {
|
||||
console.error('密码哈希失败:', error)
|
||||
throw new Error('密码加密失败')
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user