forked from jerrykrinock/CategoriesObjC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSData_AMDigest.m
33 lines (28 loc) · 850 Bytes
/
NSData_AMDigest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <openssl/evp.h>
#include <openssl/err.h>
@implementation NSData (AMDigest)
- (NSData *)md5Digest
{
// compute an MD5 digest.
EVP_MD_CTX mdctx;
unsigned char md_value[EVP_MAX_MD_SIZE];
int unsigned md_len;
EVP_DigestInit(&mdctx, EVP_md5());
EVP_DigestUpdate(&mdctx, [self bytes], [self length]);
EVP_DigestFinal(&mdctx, md_value, &md_len);
EVP_MD_CTX_cleanup(&mdctx); // added by Jerry
return [NSData dataWithBytes: md_value length: md_len];
}
- (NSData *)sha1Digest
{
// compute an SHA1 digest.
EVP_MD_CTX mdctx;
unsigned char md_value[EVP_MAX_MD_SIZE];
int unsigned md_len;
EVP_DigestInit(&mdctx, EVP_sha1());
EVP_DigestUpdate(&mdctx, [self bytes], [self length]);
EVP_DigestFinal(&mdctx, md_value, &md_len);
EVP_MD_CTX_cleanup(&mdctx); // added by Jerry
return [NSData dataWithBytes: md_value length: md_len];
}
@end