Files
ShadowsocksX-NG/ShadowsocksX-NG/Utils.swift

28 lines
654 B
Swift
Raw Normal View History

2016-06-09 00:30:08 +08:00
//
// Utils.swift
// ShadowsocksX-NG
//
// Created by on 16/6/7.
// Copyright © 2016 qiuyuzhou. All rights reserved.
//
import Foundation
extension String {
var localized: String {
return NSLocalizedString(self, tableName: nil, bundle: Bundle.main, value: "", comment: "")
2016-06-09 00:30:08 +08:00
}
}
extension Data {
2016-06-09 00:30:08 +08:00
func sha1() -> String {
let data = self
var digest = [UInt8](repeating: 0, count: Int(CC_SHA1_DIGEST_LENGTH))
CC_SHA1((data as NSData).bytes, CC_LONG(data.count), &digest)
2016-06-09 00:30:08 +08:00
let hexBytes = digest.map { String(format: "%02hhx", $0) }
return hexBytes.joined(separator: "")
2016-06-09 00:30:08 +08:00
}
}