extension ViewController{
@objc func registerAction() {
view.makeToastActivity(.center)
- let sn = "MSCL1BKZ12105000042363"
- let deviceId = "C0310000A57B"
- let productKey = "ccvUoJOLbXn"
- let secretKey = "nNRjkRpKTxvprGaW"
- MixSdk.shared.auth.register(productKey: productKey, secretKey: secretKey, deviceId: deviceId,sn:sn){[weak self] deviceSecret,error in
+ let deviceId = "281106AFB0F7"
+ let productKey = "pafOCKLiUbeVHbdZlddH"
+ let secretKey = "HHosiYUNdG42t1cTgKOzIUPOvAVMI2QT"
+ MixSdk.shared.auth.register(productKey: productKey, secretKey: secretKey, deviceId: deviceId){[weak self] model,error in
self?.view.hideToastActivity()
if let err = error{
print("\(err)")
}
else{
self?.view.makeToast("register success!")
- print(deviceSecret ?? "")
+ print(model!.deviceId)
+ print(model!.password)
+ print(model!.nonce)
}
}
}
@objc func loginAction() {
view.makeToastActivity(.center)
- let deviceId = "C0310000A57B"
- let productKey = "ccvUoJOLbXn"
- let secretKey = "nNRjkRpKTxvprGaW"
- let deviceSecret = "twLGAEo3RqlfCY3QLOjppdXkMb5I4dGC"
- MixSdk.shared.auth.login(productKey: productKey, secretKey: secretKey, deviceId: deviceId, deviceSecrect: deviceSecret){[weak self] isSuccess,error in
+ let deviceId = "281106AFB0F7"
+ let password = "RDSr+qCM3zLqTLVh3L/74B4Rhh5CsBU7D3/0KZMCknM="//注册获得
+ let nonce = "WFY51NbA4lUff3Jd"//注册获得
+ MixSdk.shared.auth.login(deviceId: deviceId, password: password,nonce:nonce){[weak self] isSuccess,error in
self?.view.hideToastActivity()
if let err = error{
self?.view.makeToast(err.msg)
</Locations>
</BreakpointContent>
</BreakpointProxy>
- <BreakpointProxy
- BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
- <BreakpointContent
- uuid = "B79AD572-041B-4C53-88E4-A6F6A6584303"
- shouldBeEnabled = "Yes"
- ignoreCount = "0"
- continueAfterRunningActions = "No"
- filePath = "MixSdk/MixSdk/Tools/MSTool.swift"
- startingColumnNumber = "9223372036854775807"
- endingColumnNumber = "9223372036854775807"
- startingLineNumber = "49"
- endingLineNumber = "49"
- landmarkName = "base64ToImage(_:)"
- landmarkType = "7">
- </BreakpointContent>
- </BreakpointProxy>
</Breakpoints>
</Bucket>
1811883F2C1A8B5200C23FAB /* CRC16.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181188372C1A8B5200C23FAB /* CRC16.swift */; };
181188402C1A8B5200C23FAB /* LRC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181188382C1A8B5200C23FAB /* LRC.swift */; };
181188452C1AC35F00C23FAB /* MSError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181188442C1AC35F00C23FAB /* MSError.swift */; };
- 181188472C1ACA6100C23FAB /* String+MD5.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181188462C1ACA6100C23FAB /* String+MD5.swift */; };
+ 181188472C1ACA6100C23FAB /* String+Crypto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181188462C1ACA6100C23FAB /* String+Crypto.swift */; };
1811884E2C1AEF0F00C23FAB /* MSTranslate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1811884D2C1AEF0F00C23FAB /* MSTranslate.swift */; };
181188572C1BE24200C23FAB /* MSStt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181188562C1BE24200C23FAB /* MSStt.swift */; };
18132AED2C1C1EA8002F6B52 /* MSTool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18132AEC2C1C1EA8002F6B52 /* MSTool.swift */; };
18204BFB2C19488900F94E69 /* Upload.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18204BF52C19488800F94E69 /* Upload.swift */; };
18204BFC2C19488900F94E69 /* HTTPSecurity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18204BF62C19488800F94E69 /* HTTPSecurity.swift */; };
18204BFD2C19488900F94E69 /* Operation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18204BF72C19488800F94E69 /* Operation.swift */; };
+ 18314A862C3CD24E0028CE50 /* MSUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 18314A842C3CD24E0028CE50 /* MSUtils.m */; };
+ 18314A872C3CD24E0028CE50 /* MSUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 18314A852C3CD24E0028CE50 /* MSUtils.h */; };
+ 18314A892C3CD55E0028CE50 /* MSAuthModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18314A882C3CD55E0028CE50 /* MSAuthModel.swift */; };
184FFC542C21B091006F664D /* MSAigcModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 184FFC532C21B091006F664D /* MSAigcModel.swift */; };
18B74A1C2C1FD44A00FABBA9 /* MSTts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18B74A1B2C1FD44A00FABBA9 /* MSTts.swift */; };
18B74A1E2C1FDDB500FABBA9 /* MSChat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18B74A1D2C1FDDB400FABBA9 /* MSChat.swift */; };
181188372C1A8B5200C23FAB /* CRC16.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CRC16.swift; sourceTree = "<group>"; };
181188382C1A8B5200C23FAB /* LRC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LRC.swift; sourceTree = "<group>"; };
181188442C1AC35F00C23FAB /* MSError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MSError.swift; sourceTree = "<group>"; };
- 181188462C1ACA6100C23FAB /* String+MD5.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+MD5.swift"; sourceTree = "<group>"; };
+ 181188462C1ACA6100C23FAB /* String+Crypto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Crypto.swift"; sourceTree = "<group>"; };
1811884D2C1AEF0F00C23FAB /* MSTranslate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MSTranslate.swift; sourceTree = "<group>"; };
181188562C1BE24200C23FAB /* MSStt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MSStt.swift; sourceTree = "<group>"; };
18132AEC2C1C1EA8002F6B52 /* MSTool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MSTool.swift; sourceTree = "<group>"; };
18204BF52C19488800F94E69 /* Upload.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Upload.swift; sourceTree = "<group>"; };
18204BF62C19488800F94E69 /* HTTPSecurity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPSecurity.swift; sourceTree = "<group>"; };
18204BF72C19488800F94E69 /* Operation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Operation.swift; sourceTree = "<group>"; };
+ 18314A842C3CD24E0028CE50 /* MSUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MSUtils.m; sourceTree = "<group>"; };
+ 18314A852C3CD24E0028CE50 /* MSUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MSUtils.h; sourceTree = "<group>"; };
+ 18314A882C3CD55E0028CE50 /* MSAuthModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MSAuthModel.swift; sourceTree = "<group>"; };
184FFC532C21B091006F664D /* MSAigcModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MSAigcModel.swift; sourceTree = "<group>"; };
18B74A1B2C1FD44A00FABBA9 /* MSTts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MSTts.swift; sourceTree = "<group>"; };
18B74A1D2C1FDDB400FABBA9 /* MSChat.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MSChat.swift; sourceTree = "<group>"; };
181188362C1A8B5200C23FAB /* UTF8.swift */,
181188372C1A8B5200C23FAB /* CRC16.swift */,
181188382C1A8B5200C23FAB /* LRC.swift */,
- 181188462C1ACA6100C23FAB /* String+MD5.swift */,
+ 181188462C1ACA6100C23FAB /* String+Crypto.swift */,
+ 18314A852C3CD24E0028CE50 /* MSUtils.h */,
+ 18314A842C3CD24E0028CE50 /* MSUtils.m */,
18132AEC2C1C1EA8002F6B52 /* MSTool.swift */,
18C42B4A2C23DA29000D8860 /* SbcToPcm.swift */,
);
18204BEF2C19457600F94E69 /* MSHttpManager.swift */,
1811882E2C1A89E600C23FAB /* MixSdk.swift */,
18204BC52C193E4B00F94E69 /* MSAuth.swift */,
+ 18314A882C3CD55E0028CE50 /* MSAuthModel.swift */,
1811884D2C1AEF0F00C23FAB /* MSTranslate.swift */,
18C42B3A2C22F284000D8860 /* MsTranslateModel.swift */,
18132AEE2C1C25CC002F6B52 /* MSAigc.swift */,
18C42BF52C242202000D8860 /* murmur3.h in Headers */,
18C42C582C242202000D8860 /* bsf.h in Headers */,
18C42C452C242202000D8860 /* avformat.h in Headers */,
+ 18314A872C3CD24E0028CE50 /* MSUtils.h in Headers */,
18C42C2C2C242202000D8860 /* channel_layout.h in Headers */,
18C42C1A2C242202000D8860 /* pixelutils.h in Headers */,
18C42C5C2C242202000D8860 /* ac3_parser.h in Headers */,
18C42C7B2C24270D000D8860 /* MSAudioConvert.swift in Sources */,
18204BC62C193E4B00F94E69 /* MSAuth.swift in Sources */,
18132AED2C1C1EA8002F6B52 /* MSTool.swift in Sources */,
- 181188472C1ACA6100C23FAB /* String+MD5.swift in Sources */,
+ 181188472C1ACA6100C23FAB /* String+Crypto.swift in Sources */,
18132AF22C1C4938002F6B52 /* SwiftWebSocket.swift in Sources */,
1811883F2C1A8B5200C23FAB /* CRC16.swift in Sources */,
181188452C1AC35F00C23FAB /* MSError.swift in Sources */,
18204BFD2C19488900F94E69 /* Operation.swift in Sources */,
1811883C2C1A8B5200C23FAB /* JSON.swift in Sources */,
181188402C1A8B5200C23FAB /* LRC.swift in Sources */,
+ 18314A892C3CD55E0028CE50 /* MSAuthModel.swift in Sources */,
18FBC2B92C38DA1D002240AF /* MSChatGptModel.swift in Sources */,
18204BFC2C19488900F94E69 /* HTTPSecurity.swift in Sources */,
18204BFB2C19488900F94E69 /* Upload.swift in Sources */,
18204BFA2C19488900F94E69 /* Request.swift in Sources */,
+ 18314A862C3CD24E0028CE50 /* MSUtils.m in Sources */,
1811882F2C1A89E600C23FAB /* MixSdk.swift in Sources */,
18C42B3B2C22F284000D8860 /* MsTranslateModel.swift in Sources */,
18C42B3F2C22F2E1000D8860 /* MSChatModel.swift in Sources */,
import CommonCrypto
/// 注册回调
-public typealias MSRegisterCallBack = (_ deviceSecret: String?,_ error:MSError?) -> Void
+public typealias MSRegisterCallBack = (_ data: MSRegisterModel?,_ error:MSError?) -> Void
/// 登录回调
public typealias MSLoginCallBack = (_ isSuccess: Bool,_ error:MSError?) -> Void
public private(set) var authorized = true
func getUrl(_ api:String)->String{
- return "https://app.api.thisiot.com/da/auth/" + api
+ return "http://180.184.206.142/bz-api/" + api
}
/// 注册
/// - deviceId: 设备ID
/// - sn: SN号
/// - completeHandler: 结果回调
- public func register(productKey:String,secretKey:String,deviceId:String,sn:String,completeHandler: @escaping MSRegisterCallBack){
+ public func register(productKey:String,secretKey:String,deviceId:String,completeHandler: @escaping MSRegisterCallBack){
let timeStamp = "\(Int(Date().timeIntervalSince1970)*1000)"
- let value = deviceId + sn + timeStamp + secretKey
- let signValue = value.md5
+ let value = deviceId + productKey + timeStamp
+ let signValue = MSUtils.string(toHmacSha1: secretKey, text: value)
let params = [
- "bid":productKey,
+ "pid":productKey,
"deviceId":deviceId,
- "signMethod":"MD5",
+ "signMethod":"HMACSHA1",
"sign":signValue,
"timeStamp":timeStamp,
- "sn":sn
]
- let url = getUrl("active")
- Logger.log(params)
+ let url = getUrl("dev/auth/active")
+ Logger.log(value,secretKey,signValue)
+ Logger.log(url,params)
HTTP.PUT(url,parameters: params,requestSerializer: JSONParameterSerializer()){ response in
DispatchQueue.main.sync {
return
}
guard let dict = dict else {return completeHandler(nil,error)}
- if let result = dict["success"] as? Bool,result == true,let data = dict["data"] as? [String:Any], let deviceSecret = data["deviceSecret"] as? String{
- completeHandler(deviceSecret,nil)
+ if let result = dict["success"] as? Bool,result == true,let dataDict = dict["data"] as? [String:Any]{
+ let model = MSRegisterModel()
+ model.deviceId = dataDict["deviceId"] as? String ?? ""
+ model.password = dataDict["password"] as? String ?? ""
+ model.nonce = dataDict["nonce"] as? String ?? ""
+ completeHandler(model,nil)
}
else{
completeHandler(nil,MSError.reponseError(dict["code"] as? Int ?? 0,dict["msg"] as? String ?? ""))
/// - deviceId: 设备ID
/// - deviceSecrect: 注册返回的密码
/// - completeHandler: 结果回调
- public func login(productKey:String,secretKey:String,deviceId:String,deviceSecrect:String,completeHandler: @escaping MSLoginCallBack){
- let timeStamp = "\(Int(Date().timeIntervalSince1970*1000))"
- let value = deviceId + deviceSecrect + timeStamp + secretKey
- let signValue = value.md5
+ public func login(deviceId:String,password:String,nonce:String,completeHandler: @escaping MSLoginCallBack){
let params = [
- "bid":productKey,
"deviceId":deviceId,
- "deviceSecret":deviceSecrect,
- "timestamp":timeStamp,
- "signMethod":"MD5",
- "sign":signValue
+ "password":password,
+ "nonce":nonce,
]
- let url = getUrl("login")
- Logger.log(params)
+
+
+ let url = getUrl("dev/auth/sign_in")
+ Logger.log(url,params)
HTTP.POST(url,parameters: params,requestSerializer: JSONParameterSerializer()){ response in
DispatchQueue.main.sync {
--- /dev/null
+//
+// MSAuthModel.swift
+// MixSdk
+//
+// Created by incar on 2024/7/9.
+//
+
+import Foundation
+///// 注册返回模型
+//public class MSRegisterModel:Codable{
+// /// 是否成功
+// public var success:Bool = false
+// /// 提示语
+// public var msg:String = "请求失败"
+// /// 状态码
+// public var code:Int = 400
+// /// 内容
+// public var data:MSRegisterData?
+//
+//}
+/// 注册返回模型
+public class MSRegisterModel{
+ /// 设备ID
+ public var deviceId:String = ""
+ /// 设备密码
+ public var password:String = ""
+ /// 16个字符的随机字符串
+ public var nonce:String = ""
+}
//
#import "AudioDecode/AiAudioDecoder.h"
+#import "Tools/MSUtils.h"
--- /dev/null
+//
+// AiMouseTools.h
+// AiMouse
+//
+// Created by incar on 2024/2/28.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface MSUtils : NSObject
++ (NSArray *)stringToArray:(NSString *)jsonString;
++ (NSString *)arrayToString:(NSArray *)arr;
+
++ (NSDictionary *)stringToDictionary:(NSString *)jsonString;
++ (NSString *)dictionaryToString:(NSDictionary *)dic;
+
++ (NSDictionary *)dataToDictionary:(NSData *)jsonData;
++ (NSData *)dictionaryToData:(NSDictionary *)dicJson;
+
+
++ (NSString *)dataToHexString:(NSData *)data;
+
++ (NSString *)dataToHexString_placeholder:(NSData *)data;
+
++ (NSData *)hexStringToData:(NSString *)hexStr ;
+
++ (NSString *)dataToUtf8String:(NSData *)data;
+
++ (NSString *)stringTomd5:(NSString *)str;
+
++ (NSString *)stringToHmacSha1:(NSString*)key text:(NSString*)text;
+
++ (NSString *)MD5ForUpper32:(NSString *)str;
+@end
+
+NS_ASSUME_NONNULL_END
--- /dev/null
+//
+// AiMouseTools.m
+// AiMouse
+//
+// Created by incar on 2024/2/28.
+//
+
+#import "MSUtils.h"
+#import <CommonCrypto/CommonCryptor.h>
+#include <CommonCrypto/CommonDigest.h>
+#include <CommonCrypto/CommonHMAC.h>
+
+@implementation MSUtils
++ (NSArray *)stringToArray:(NSString *)jsonString{
+ NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
+ NSError *error;
+ NSArray *arr = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
+ return arr;
+}
++ (NSString *)arrayToString:(NSArray *)arr{
+ NSError *error;
+ NSData *jsonData = [NSJSONSerialization dataWithJSONObject:arr options:NSJSONWritingPrettyPrinted error:&error];
+ NSString * string = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
+ return string;
+}
++ (NSDictionary *)stringToDictionary:(NSString *)jsonString{
+ NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
+ if (jsonData == nil) {
+ return nil;
+ }
+ NSError *error;
+ NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
+ return dict;
+}
++ (NSString *)dictionaryToString:(NSDictionary *)dic{
+ if ([dic isKindOfClass:[NSDictionary class]]) {
+ NSError *error;
+ NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&error];
+ NSString * string = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
+ return string;
+ }
+ else{
+ return @"";
+ }
+}
+
++ (NSDictionary *)dataToDictionary:(NSData *)jsonData{
+ if (![jsonData isKindOfClass:[NSData class]] || jsonData.length < 1) {
+ return nil;
+ }
+ id jsonObj = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:nil];
+ if (![jsonObj isKindOfClass:[NSDictionary class]]) {
+ return nil;
+ }
+ return [NSDictionary dictionaryWithDictionary:(NSDictionary *)jsonObj];
+}
+
+
++ (NSData *)dictionaryToData:(NSDictionary *)dicJson{
+ if (![dicJson isKindOfClass:[NSDictionary class]]) {
+ return nil;
+ }
+ NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dicJson options:0 error:nil];
+ if (![jsonData isKindOfClass:[NSData class]]) {
+ return nil;
+ }
+ return jsonData;
+}
+
++ (NSString *)dataToHexString:(NSData *)data {
+ NSUInteger length = data.length;
+ NSMutableString *result = [NSMutableString stringWithCapacity:length * 2];
+ const unsigned char *byte = data.bytes;
+ for (int i = 0; i < length; i++, byte++) {
+ [result appendFormat:@"%02X", *byte];
+ }
+ return result;
+}
+
++ (NSString *)dataToHexString_placeholder:(NSData *)data {
+ NSUInteger length = data.length;
+ NSString *placeholder = @" ";
+ NSMutableString *result = [NSMutableString stringWithCapacity:length * 2];
+ const unsigned char *byte = data.bytes;
+ for (int i = 0; i < length; i++, byte++) {
+ [result appendFormat:@"%02X%@", *byte, placeholder];
+ }
+ return result;
+}
+
++ (NSData *)hexStringToData:(NSString *)hexStr {
+ hexStr = [hexStr stringByReplacingOccurrencesOfString:@" " withString:@""];
+ hexStr = [hexStr lowercaseString];
+ NSUInteger len = hexStr.length;
+ if (!len) return nil;
+ unichar *buf = malloc(sizeof(unichar) * len);
+ if (!buf) return nil;
+ [hexStr getCharacters:buf range:NSMakeRange(0, len)];
+
+ NSMutableData *result = [NSMutableData data];
+ unsigned char bytes;
+ char str[3] = { '\0', '\0', '\0' };
+ int i;
+ for (i = 0; i < len / 2; i++) {
+ str[0] = buf[i * 2];
+ str[1] = buf[i * 2 + 1];
+ bytes = strtol(str, NULL, 16);
+ [result appendBytes:&bytes length:1];
+ }
+ free(buf);
+ return result;
+}
+
++ (NSString *)dataToUtf8String:(NSData *)data {
+ if (data.length > 0) {
+ return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
+ }
+ return @"";
+}
+
+
++ (NSString *)stringTomd5:(NSString *)str {
+ if (str.length == 0) {
+ return nil;
+ }
+ // 初始化C字符数组
+ const char* original_str = (const char *)[[str dataUsingEncoding:NSUTF8StringEncoding] bytes];
+ // 盛放数字校验的字符数组(长度为16bytes)
+ unsigned char digist[CC_MD5_DIGEST_LENGTH]; //CC_MD5_DIGEST_LENGTH = 16
+ CC_MD5(original_str, (uint)strlen(original_str), digist);
+ // NSMutableString* outPutStr = [NSMutableString stringWithCapacity:10];
+ NSMutableString* outPutStr = [NSMutableString new];
+ for(int i =0; i<CC_MD5_DIGEST_LENGTH;i++){
+ [outPutStr appendFormat:@"%02X",digist[i]];//小写x表示输出的是小写MD5,大写X表示输出的是大写MD5
+ }
+ return outPutStr;
+}
+
+//HmacSHA1加密
++ (NSString *)stringToHmacSha1:(NSString*)key text:(NSString*)text{
+ const char *cKey = [key cStringUsingEncoding:NSUTF8StringEncoding];
+ const char *cData = [text cStringUsingEncoding:NSUTF8StringEncoding];
+ uint8_t cHMAC[CC_SHA1_DIGEST_LENGTH];
+ CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
+ //NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:CC_SHA1_DIGEST_LENGTH];
+ NSString *hash;
+ NSMutableString * output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];
+ for(int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++)
+ [output appendFormat:@"%02X", cHMAC[i]];
+ hash = output;
+ return hash;
+}
+
++ (NSString *)MD5ForUpper32:(NSString *)str {
+ const char* input = [str UTF8String];
+ unsigned char result[CC_MD5_DIGEST_LENGTH];
+ CC_MD5(input, (CC_LONG)strlen(input), result);
+ // 'CC_MD5' is deprecated: first deprecated in iOS 13.0 - This function is cryptographically broken and should not be used in security contexts. Clients should migrate to SHA256 (or stronger).
+ NSMutableString *digest = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
+ for (NSInteger i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
+ [digest appendFormat:@"%02X", result[i]];
+ }
+
+ return digest;
+}
+@end
+
import Foundation
import CommonCrypto
+
+import CryptoKit
+
extension String {
/// 原生md5
var md5: String {
return digest.map { String(format: "%02X", $0) }.joined()
}
+
+
}
+