IOS string encryption to MD5
1 # Import <Commoncrypto/commondigest. h>
2
3 + (Nsstring *) MD5 :( nsstring *) Str
4 {
5 Const Char * CSTR = [STR utf8string];
6 Unsigned Char Result [ 16 ];
7 Cc_md5 (CSTR, strlen (CSTR), result );
8 Return [Nsstring stringwithformat: @" % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x " ,
9 Result [ 0 ], Result [ 1 ], Result [ 2 ], Result [ 3 ],
10 Result [ 4 ], Result [ 5 ], Result [ 6 ], Result [ 7 ],
11 Result [ 8 ], Result [ 9 ], Result [ 10 ], Result [ 11 ],
12 Result [ 12 ], Result [ 13 ], Result [ 14 ], Result [ 15 ]
13 ];
14 }
The iPhone processes large files and detects MD5 Code
1 + (Nsstring *) filemd5 :( nsstring *) path
2 {
3 Nsfilehandle * handle = [nsfilehandle filehandleforreadingatpath: path];
4 If (Handle = nil) Return @" Error getting file MD5 " ; // File didnt exist
5
6 Cc_md5_ctx MD5;
7
8 Cc_md5_init (& MD5 );
9
10 Bool done = no;
11 While (! Done)
12 {
13 Nsdata * filedata = [Handle readdataoflength: chunk_size];
14 Cc_md5_update (& MD5, [filedata bytes], [filedata length]);
15 If ([Filedata length] = 0 ) Done = yes;
16 }
17 Unsigned Char Digest [cc_md5_digest_length];
18 Cc_md5_final (Digest, & MD5 );
19 Nsstring * s = [nsstring stringwithformat: @" % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x % 02x " ,
20 Digest [ 0 ], Digest [ 1 ],
21 Digest [ 2 ], Digest [ 3 ],
22 Digest [ 4 ], Digest [ 5 ],
23 Digest [ 6 ], Digest [ 7 ],
24 Digest [ 8 ], Digest [9 ],
25 Digest [ 10 ], Digest [ 11 ],
26 Digest [ 12 ], Digest [ 13 ],
27 Digest [ 14 ], Digest [ 15 ];
28 Return S;
29 }