加密方法如下
- (NSString *)HmacSha1WithSecret:(NSString *)key
{
const char *cKey = [key cStringUsingEncoding:NSASCIIStringEncoding];
const char *cData = [self cStringUsingEncoding:NSASCIIStringEncoding];
unsigned char cHMAC[CC_SHA1_DIGEST_LENGTH];
CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)];
NSString *hash = [QNUrlSafeBase64 encodeData:HMAC];
return hash;
}
MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, and their corresponding HMAC algorithms are all hash algorithms, also called digest algorithms, one-way operations, irreversible, so There is no way to decrypt it. However, it can be cracked through brute force (generating strings one by one in order), which of course will take a very long time, and the result of this test may not be the original result, because there are indeed multiple source data that can calculate the same hash value. column results.