objective-c - 为什么我们iOS加密出来的和安卓加密出来的不同?
滿天的星座
滿天的星座 2017-04-25 09:03:48
0
1
657

安卓加密出来的是[B@42a6f4d8 我们iOS加密出来的是6132896cb90f07ff8f5313990324016816d54f6b

还有

baseStr = [[NSString alloc] initWithData:[QNUrlSafeBase64 decodeString:HIMAStr] encoding:NSUTF8StringEncoding]; [QNUrlSafeBase64 decodeString:HIMAStr]是有值的 但是返回出来却是nil这是为什么呀?这是我的代码 请大神们指点下!感激不尽!!!

滿天的星座
滿天的星座

membalas semua(1)
PHPzhong

Nasib baik, saya kebetulan menggunakan Qiniu baru-baru ini:

- (NSString *)genToken
{
    static NSUInteger expireTime = 0;
    static NSString *cachedSign = nil;
    NSUInteger now = (NSUInteger)[NSDate date].timeIntervalSince1970;
    if (now > expireTime) {
        expireTime = now + 3600 - 60;
        NSDictionary *policy = @{
                                 @"scope": _bucket,
                                 @"deadline": @(expireTime + 60),
                                 @"returnBody": @"{\"key\":$(key),\"name\":$(fname),\"size\":$(fsize),\"w\":$(imageInfo.width),\"h\":$(imageInfo.height),\"hash\":$(etag)}"
                                 };
        NSString *encodedPolicy = [[NSJSONSerialization dataWithJSONObject:policy
                                                                   options:0
                                                                     error:NULL] base64EncodedStringWithOptions:0];
        encodedPolicy = [encodedPolicy stringByReplacingOccurrencesOfString:@"+" withString:@"-"];
        encodedPolicy = [encodedPolicy stringByReplacingOccurrencesOfString:@"/" withString:@"_"];

        const char *text = [encodedPolicy cStringUsingEncoding:NSASCIIStringEncoding];
        const char *key = [_secretKey cStringUsingEncoding:NSASCIIStringEncoding];
        char cHMAC[CC_SHA1_DIGEST_LENGTH];
        CCHmac(kCCHmacAlgSHA1, key, strlen(key), text, strlen(text), cHMAC);

        NSString *sign = [[NSString alloc] initWithData:[NSData dataWithBytes:cHMAC
                                                                       length:sizeof(cHMAC)]
                                               encoding:NSASCIIStringEncoding];
        NSString *encodedSign = sign.toBase64String;
        encodedSign = [encodedSign stringByReplacingOccurrencesOfString:@"+" withString:@"-"];
        encodedSign = [encodedSign stringByReplacingOccurrencesOfString:@"/" withString:@"_"];

        cachedSign = [NSString stringWithFormat:@"%@:%@:%@", _accessKey, encodedSign, encodedPolicy];
    }
    return cachedSign;
}
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan