Reputation: 14845
I have the following code in Swift (iOS) to do some basic data encryption:
import Foundation
import CommonCrypto
// ...
static func sha256(_ data: Data) -> Data? {
guard let res = NSMutableData(length: Int(CC_SHA256_DIGEST_LENGTH)) else { return nil }
CC_SHA256((data as NSData).bytes, CC_LONG(data.count), res.mutableBytes.assumingMemoryBound(to: UInt8.self))
return res as Data
}
I'm unfamiliar with encryption in PHP but need this simple function converted for a small project.
Upvotes: -1
Views: 159