获取NSData数据的md5(以视频为例)

视频为例如下:

//导入
#include 

/// 获取视频MD5方法
/// @param url 视频url,暂未用到
/// @param localAsset 本地的asset数据
- (void)getPhoneDateVideo:(NSURL *)url phAsset:(PHAsset *)localAsset
{
    PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
    options.version = PHImageRequestOptionsVersionCurrent;
    options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
    
    PHImageManager *manager = [PHImageManager defaultManager];
    [manager requestAVAssetForVideo:localAsset
                            options:options
                      resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
        // asset 类型为 AVURLAsset  为此资源的fileURL
        // 
        AVURLAsset *urlAsset = (AVURLAsset *)asset;
        // 视频数据
        NSData *vedioData = [NSData dataWithContentsOfURL:urlAsset.URL];
        NSLog(@"%@",vedioData);
        [vedioData writeToFile:KVideoUrlPath atomically:YES];
        dispatch_async(dispatch_get_main_queue(), ^{
             //获取视频MD5
            NSData *data = vedioData;

            unsigned char digest[CC_MD5_DIGEST_LENGTH];
            
            CC_MD5( data.bytes, (CC_LONG)data.length, digest );
            
            NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
            
            for( int i = 0; i < CC_MD5_DIGEST_LENGTH; i++ )
            {
                [output appendFormat:@"%02x", digest[i]];
                
            }
            NSLog(@"视频的MD5:%@",output);
        });
    }];

}

你可能感兴趣的:(获取NSData数据的md5(以视频为例))