Files
e-party-iOS/yana/Utils/Extensions/String+MD5.swift
edwinQQQ c470dba79c feat: 更新项目配置和功能模块
- 修改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项目配置,调整版本号和启动画面设置。
2025-07-09 16:14:19 +08:00

39 lines
1.5 KiB
Swift
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
///
/// MD5iOS 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()
}
}
}