How can I create SHA256 with two keys in swift , ios

333 views Asked by At

we have used SHA256 in our objective C project using IGSignature library. now we are converting objective-C project to swift. used common crypto, but it use only one key. if anyone knows about this hope your help.

1

There are 1 answers

0
Krishna Datt Shukla On

Hope following code will help you....

    var post = String()
    post += "FIRSTKEY=\("value")"
    post += "SECONDKEY=\("value")"



    let shaEncode =   self.sha256(string: post)
    print("SHA-> \(datastring)")

func sha256(string: String) -> Data? {
    guard let messageData = string.data(using:String.Encoding.utf8) else { return nil }
    var digestData = Data(count: Int(CC_SHA256_DIGEST_LENGTH))

    _ = digestData.withUnsafeMutableBytes {digestBytes in
        messageData.withUnsafeBytes {messageBytes in
            CC_SHA256(messageBytes, CC_LONG(messageData.count), digestBytes)
        }
    }
    return digestData
}