
- 修改Package.swift以支持iOS 15和macOS 12。 - 更新swift-tca-architecture-guidelines.mdc中的alwaysApply设置为false。 - 注释掉AppDelegate中的NIMSDK导入,移除不再使用的NIMConfigurationManager和NIMSessionManager文件。 - 添加新的API相关文件,包括EMailLoginFeature、IDLoginFeature和相关视图,增强登录功能。 - 更新APIConstants和APIEndpoints以反映新的API路径。 - 添加本地化支持文件,包含英文和中文简体的本地化字符串。 - 新增字体管理和安全工具类,支持AES和DES加密。 - 更新Xcode项目配置,调整版本号和启动画面设置。
39 lines
1.5 KiB
Swift
39 lines
1.5 KiB
Swift
import Foundation
|
||
import CommonCrypto
|
||
import CryptoKit
|
||
|
||
// MARK: - String Hash Extensions
|
||
extension String {
|
||
/// 计算字符串的SHA256哈希值(推荐使用)
|
||
/// - Returns: SHA256哈希值的小写十六进制字符串
|
||
@available(iOS 13.0, *)
|
||
func sha256() -> String {
|
||
let data = Data(self.utf8)
|
||
let digest = SHA256.hash(data: data)
|
||
return digest.compactMap { String(format: "%02x", $0) }.joined()
|
||
}
|
||
|
||
/// 计算字符串的MD5哈希值(已弃用,仅用于兼容性)
|
||
///
|
||
/// ⚠️ 警告:MD5在iOS 13.0后已被弃用,因为它在加密学上是不安全的
|
||
/// 建议使用 sha256() 方法替代
|
||
///
|
||
/// - Returns: MD5哈希值的小写十六进制字符串
|
||
func md5() -> String {
|
||
if #available(iOS 13.0, *) {
|
||
// iOS 13+ 使用 CryptoKit 的 Insecure.MD5
|
||
let data = Data(self.utf8)
|
||
let digest = Insecure.MD5.hash(data: data)
|
||
return digest.compactMap { String(format: "%02x", $0) }.joined()
|
||
} else {
|
||
// iOS 13 以下使用 CommonCrypto
|
||
let data = Data(self.utf8)
|
||
let hash = data.withUnsafeBytes { bytes -> [UInt8] in
|
||
var hash = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
|
||
CC_MD5(bytes.baseAddress, CC_LONG(data.count), &hash)
|
||
return hash
|
||
}
|
||
return hash.map { String(format: "%02x", $0) }.joined()
|
||
}
|
||
}
|
||
} |