开发者

iphone username password MD5

I am having one UITextField label as Password and User开发者_JAVA百科name. I have to convert UItextField (input from the keyboard) to MD5 and store it to another UITextfield. Code would be appreaciated.


Have a look at the documentation for OpenSSL, which is part of the iOS SDK. It contains a very simple MD5 hashing function called MD5() (it's in <openssl/md5.h>).


I realize this has been answered but wondered if a complete code example would help others:

#import <CommonCrypto/CommonDigest.h>

+ (NSString*)md5HexDigest:(NSString*)input 
{
    const char* str = [input UTF8String];
    unsigned char result[CC_MD5_DIGEST_LENGTH];
    CC_MD5(str, strlen(str), 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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜