Files
e-party-iOS/yana/Utils/Extensions/String+HashTest.swift
edwinQQQ f9f3dec53f feat: 更新Podfile和Podfile.lock,移除Alamofire依赖并添加API认证机制文档
- 注释掉Podfile中的Alamofire依赖,更新Podfile.lock以反映更改。
- 在yana/APIs/API-README.md中新增自动认证Header机制的详细文档,描述其工作原理、实现细节及最佳实践。
- 在yana/yanaApp.swift中将print语句替换为debugInfo以增强调试信息的输出。
- 在API相关文件中实现用户认证状态检查和相关header的自动添加逻辑,提升API请求的安全性和用户体验。
- 更新多个文件中的日志输出,确保在DEBUG模式下提供详细的调试信息。
2025-07-11 16:53:46 +08:00

83 lines
2.6 KiB
Swift

import Foundation
///
/// MD5 SHA256
struct StringHashTest {
///
static func runTests() {
debugInfo("🧪 开始测试字符串哈希方法...")
let testStrings = [
"hello world",
"test123",
"key=rpbs6us1m8r2j9g6u06ff2bo18orwaya",
"phone=encrypted_phone&password=encrypted_password&client_id=erban-client&key=rpbs6us1m8r2j9g6u06ff2bo18orwaya"
]
for testString in testStrings {
debugInfo("\n📝 测试字符串: \"\(testString)\"")
// MD5
let md5Result = testString.md5()
debugInfo(" MD5: \(md5Result)")
// SHA256 (iOS 13+)
if #available(iOS 13.0, *) {
let sha256Result = testString.sha256()
debugInfo(" SHA256: \(sha256Result)")
} else {
debugInfo(" SHA256: 不支持 (需要 iOS 13+)")
}
}
debugInfo("\n✅ 哈希方法测试完成")
}
///
static func verifyKnownHashes() {
debugInfo("\n🔍 验证已知哈希值...")
// "hello world" MD5 "5d41402abc4b2a76b9719d911017c592"
let testString = "hello world"
let expectedMD5 = "5d41402abc4b2a76b9719d911017c592"
let actualMD5 = testString.md5()
if actualMD5 == expectedMD5 {
debugInfo("✅ MD5 验证通过: \(actualMD5)")
} else {
debugError("❌ MD5 验证失败:")
debugError(" 期望: \(expectedMD5)")
debugError(" 实际: \(actualMD5)")
}
// SHA256
if #available(iOS 13.0, *) {
let expectedSHA256 = "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
let actualSHA256 = testString.sha256()
if actualSHA256 == expectedSHA256 {
debugInfo("✅ SHA256 验证通过: \(actualSHA256)")
} else {
debugError("❌ SHA256 验证失败:")
debugError(" 期望: \(expectedSHA256)")
debugError(" 实际: \(actualSHA256)")
}
}
}
}
// MARK: - 使
/*
//
StringHashTest.runTests()
StringHashTest.verifyKnownHashes()
//
debugInfo("Test MD5:", "hello".md5())
if #available(iOS 13.0, *) {
debugInfo("Test SHA256:", "hello".sha256())
}
*/