Swift2 0 字符串分類 MD5加密

import UIKitios

class iosMD5: NSObject {

                }
                extension String{
                    func md5() ->String!{
                        let str = self.cStringUsingEncoding(NSUTF8StringEncoding)
                        let strLen = CUnsignedInt(self.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))
                        let digestLen = Int(CC_MD5_DIGEST_LENGTH)
                        let result = UnsafeMutablePointer<CUnsignedChar>.alloc(digestLen)
                        CC_MD5(str!, strLen, result)
                        let hash = NSMutableString()
                        for i in 0 ..< digestLen {
                            hash.appendFormat("%02x", result[i])
                        }
                        result.destroy()
                        return String(format: hash as String)
                    }
                }
複製代碼

使用app

let  str =  "加密內容".md5() //加密
複製代碼
  • ######看我那麼可愛n(≧▽≦)n
  • 關注個人微薄 (梁同桌):http://weibo.com/tongrenyinsheng
  • 我的網站(同人音聲) http://www.tongrenyinsheng.com
  • ios 我的寫的app (同人音聲)ASMR音樂
相關文章
相關標籤/搜索