加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在swift中使用md5

发布时间:2020-12-14 02:03:34 所属栏目:百科 来源:网络整理
导读:在swift中使用md5 by 伍雪颖 在ProjectName-Bridging-Header.h中添加 #import CommonCrypto/CommonCrypto.h extension String { var MD5: String { let cString = self . cStringUsingEncoding ( NSUTF8StringEncoding ) let length = CUnsignedInt ( length

在swift中使用md5

by 伍雪颖


在ProjectName-Bridging-Header.h中添加
#import <CommonCrypto/CommonCrypto.h>
extension String {
var MD5: String {
let cString = self . cStringUsingEncoding ( NSUTF8StringEncoding )
let length = CUnsignedInt (
lengthOfBytesUsingEncoding ( NSUTF8StringEncoding )
)
let result = UnsafeMutablePointer < CUnsignedChar >. alloc ( Int ( CC_MD5_DIGEST_LENGTH ))
CC_MD5 (cString!,length,result)
return String (format: "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" ,
result[
0 ],result[ 1 ],216)">2 ],216)">3 ],216)">4 ],216)">5 ],216)">6 ],216)">7 ],216)">8 ],216)">9 ],216)">10 ],216)">11 ],216)">12 ],216)">13 ],216)">14 ],216)">15 ])
}
}

使用:

println("rain".MD5)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读