• NSData 转 md5


    NSData 转 md5


    NSData+MD5Digest.h

    #import <Foundation/Foundation.h>
    
    
    
    @interface NSData (MD5Digest)
    
    
    
    +(NSData *)MD5Digest:(NSData *)input;
    
    -(NSData *)MD5Digest;
    
    
    
    +(NSString *)MD5HexDigest:(NSData *)input;
    
    -(NSString *)MD5HexDigest;
    
    
    
    @end
    

    NSData+MD5Digest.m

    #import "NSData+MD5Digest.h"
    
    #import <CommonCrypto/CommonDigest.h>
    
    
    
    @implementation NSData (MD5)
    
    
    
    +(NSData *)MD5Digest:(NSData *)input {
    
    unsigned char result[CC_MD5_DIGEST_LENGTH];
    
    
    
    CC_MD5(input.bytes, (CC_LONG)input.length, result);
    
    return [[NSData alloc] initWithBytes:result length:CC_MD5_DIGEST_LENGTH];
    
    }
    
    
    
    -(NSData *)MD5Digest {
    
    return [NSData MD5Digest:self];
    
    }
    
    
    
    +(NSString *)MD5HexDigest:(NSData *)input {
    
    unsigned char result[CC_MD5_DIGEST_LENGTH];
    
    
    
    CC_MD5(input.bytes, (CC_LONG)input.length, result);
    
    NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH*2];
    
    for (int i = 0; i<CC_MD5_DIGEST_LENGTH; i++) {
    
        [ret appendFormat:@"%02x",result[i]];
    
    }
    
    return ret;
    
    }
    
    
    
    -(NSString *)MD5HexDigest {
    
    return [NSData MD5HexDigest:self];
    
    }
    
    
    
    @end
    

    源github地址: suiyi

  • 相关阅读:
    运算放大器
    阻抗模型
    mysql优化
    tomcat调优
    jvm调优
    springboot使用
    deploy工程到nexus
    Spring data elasticsearch使用
    kibana使用
    笔记
  • 原文地址:https://www.cnblogs.com/sunyanyan/p/5216843.html
Copyright © 2020-2023  润新知