MD5 algorithm in Objective C
How to calculate the MD5 in objective C ?
md5 is available on the iPhone and can be added as an extension for ie NSString and NSData like below.
MyExtensions.h
@interfaceNSString(MyExtensions)-(NSString*) md5;@end@interfaceNSData(MyExtensions)-(NSString*)md5;@end
MyExtensions.m
#import "MyExtensions.h"#import <CommonCrypto/CommonDigest.h> // Need to import for CC_MD5 access@implementationNSString(MyExtensions)-(NSString*) md5
{constchar*cStr =[self UTF8String];unsignedchar result[16];
CC_MD5( cStr, strlen(cStr), result );// This is the md5 callreturn[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@implementationNSData(MyExtensions)-(NSString*)md5
{unsignedchar result[16];
CC_MD5( self.bytes, self.length, result );// This is the md5 callreturn[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
EDIT
Added NSData md5 because I needed it myself and thought this is a good place to save this little snippet...
MD5 algorithm in Objective C的更多相关文章
- [信安Presentation]一种基于GPU并行计算的MD5密码解密方法
-------------------paper--------------------- 一种基于GPU并行计算的MD5密码解密方法 0.abstract1.md5算法概述2.md5安全性分析3.基 ...
- md5 (c语言)
/** * \file md5.h * * \brief MD5 message digest algorithm (hash function) * * Copyright (C) 2006-201 ...
- 根据UUID和MD5, 生成可以用作Token的字符串
import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util. ...
- asp中的md5/sha1/sha256算法收集
对于asp这种古董级的技术,这年头想找一些有用的资料已经不容易了,下面是一些常用的加密算法: md5 (将以下代码另存为md5.inc) <% Private Const BITS_TO_A_B ...
- 密码加密md5和sha
package cn.springmvc.util;import java.security.MessageDigest;import java.security.NoSuchAlgorithmExc ...
- md5sum.c, md5.c, md5.h
md5sum.c #include <stdio.h> #include <stdlib.h> #include "md5.h" #pragma warni ...
- c#计算文件的MD5值
代码: /// <summary> /// 计算文件的 MD5 值 /// </summary> /// <param name="fileName" ...
- JQuery - MD5加密
效果: JS代码: 命名为任意名称,一般为:Jquery.md5.js /** * jQuery MD5 hash algorithm function * * <code> * Calc ...
- C# 计算字符串/文件的哈希值(MD5、SHA)
原文 C# 计算字符串的哈希值(MD5.SHA) 已做修改 一.关于本文 本文中是一个类库,包括下面几个函数: /// 1)计算32位MD5码(大小写):Hash_MD5_32 /// 2)计算16位 ...
随机推荐
- Visual C++ 连连看游戏源代码
点击下载
- 在同一个sql语句中如何写不同条件的count数量 (转)
end) end)"描述名称2" from 表名 t
- [oldboy-django][2深入django]rest-framework教程
# rest-framework教程 - settings.py INSTALL-APPS = [ 'snippets', # app 'rest-framework', ] - 创建model # ...
- 201621123034 《Java程序设计》第2周学习总结
1. 本周学习总结 本周学习了基本数据类型.包装类,自动装箱与自动拆箱.数组.ArrayList.包装类可以更加方便的转换基本数据类型,而其存放的是对象的引用,而非对象本身,在对其内容进行比较时,要使 ...
- 历史Linux镜像的问题修复方案
历史Linux镜像创建的ECS云服务器,可能存在NTP没有配置,YUM没有配置,还可能存在最近暴漏较高的安全漏洞,请按照以下步骤进行修复,可以让您的云服务器更加安全,还可以使用阿里云提供的YUM服务进 ...
- iOS App启动图不显示的解决办法.
1. 正常来说,启动图以及App图标需按照命名规则命名, 但是命名不规范并不影响显示; 2. 设置启动图的两种方法: (1) iOS 8—xcode 6 之后新出LaunchScreen.s ...
- 山贼集团 (group)
山贼集团 (group) 题目描述 某山贼集团在绿荫村拥有强大的势力,整个绿荫村由N个连通的小村落组成,并且保证对于每两个小村落有且仅有一条简单路径相连.小村落用阿拉伯数字编号为1,2,3,4,-,n ...
- docke存储
1.Docker提供三种不同的方式将数据从宿主机挂载到容器中:volumes,bind mounts和tmpfs.volumes:Docker管理宿主机文件系统的一部分(/var/lib/docker ...
- hdu 1503 最长公共子序列
/* 给两个串a,b.输出一个最短的串(含等于a的子序列且含等于b的子序列) */ #include <iostream> #include <cstdio> #include ...
- [LeetCode] Count and Say 字符串
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...