解决方案 »
- 初学oc一个简单的问题。
- iphone 开发 关于UIpagecontrol 的使用问题
- EGOImageLoading的使用问题
- 用OC语言,编译一款推箱子游戏。
- 菜鸟请问,下面这个问题原因在哪呢?
- 在线等,关于iOS中从本地相册调取图片上传到界面中
- cocoa pods gem - v出现了问题 怎么样解决啊
- 服务器用C语言写的,客户请求url,服务器怎么返回一个json字符串
- 求助 友盟只出报错 No occurrence for index path (null)
- ubuntu 上vmware虚拟机(macos),通过usb连接apple iphone失败
- 手势
- ios企业证书打包操作
- (NSString *)md5
{
const char *cStr = [self UTF8String];
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5( cStr, strlen(cStr), result ); // This is the md5 call
return [NSString stringWithFormat:
@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
result[0], result[1], result[2], result[3],
result[4], result[5], result[6], result[7],
result[8], result[9], result[10], result[11],
result[12], result[13], result[14], result[15]
];
}
@end@implementation NSData (MyAdditions)
- (NSString*)md5
{
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5( self.bytes, self.length, result ); // This is the md5 call
return [NSString stringWithFormat:
@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
result[0], result[1], result[2], result[3],
result[4], result[5], result[6], result[7],
result[8], result[9], result[10], result[11],
result[12], result[13], result[14], result[15]
];
}
@end
md5 后你再仿照他的java 代码做位运算就行了。
C语言中有>>呀,还是找个C语言版本的md5加密吧,oc中应该可以直接调用才对。
const char *md = [md5 UTF8String];
NSUInteger j = md5.length;
char str[j * 2];
NSUInteger k = 0;
for (int i = 0; i < j; i++) {
Byte byte0 = md[i];
str[k++] = (char)@[@'0',@'1',@'2',@'3'][byte0 >> 4 & 0x7FFFFFFF & 0xf];
str[k++] = (char)@[@'0',@'1',@'2',@'3'][byte0 & 0xf];
}由于OC没有<<<运算符,我是自己把高位补零的