【问题标题】:How can I create SHA256 with two keys in swift , ios如何在 swift 、 ios 中使用两个键创建 SHA256
【发布时间】:2016-12-21 17:56:21
【问题描述】:

我们在使用 IGSignature 库的目标 C 项目中使用了 SHA256。 现在我们正在将objective-C项目转换为swift。使用普通加密,但它只使用一个密钥。如果有人知道这个希望你的帮助。

【问题讨论】:

    标签: ios swift3 sha256


    【解决方案1】:

    希望以下代码对您有所帮助....

        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
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-22
      • 2021-04-04
      • 1970-01-01
      • 2018-02-18
      • 2012-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-28
      相关资源
      最近更新 更多