pscbonline-ios/PSCBOnline/Sources/Helpers/DigestHelper.swift

30 lines
655 B
Swift
Raw Normal View History

2024-07-08 15:20:00 +03:00
//
// DigestHelper.swift
// PSCB-OOS-iOS
//
// Created by Antonov Ilia on 28.10.2020.
//
import Foundation
import CommonCrypto
public struct DigestHelper {
public static func sha256String(_ string: String) -> String {
let data = string.data(using: .utf8)!
var hash = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
var sign = ""
data.withUnsafeBytes {
_ = CC_SHA256($0.baseAddress, CC_LONG(data.count), &hash)
}
for byte in hash {
sign += String(format: "%02x", UInt8(byte))
}
return sign.lowercased()
}
}