我有一个使用SSL的应用程序,以及此代码的CommonCrypto库:
enum HMACAlgorithm {
case MD5, SHA1, SHA224, SHA256, SHA384, SHA512
func toCCEnum() -> CCHmacAlgorithm {
var result: Int = 0
switch self {
case .MD5:
result = kCCHmacAlgMD5
case .SHA1:
result = kCCHmacAlgSHA1
case .SHA224:
result = kCCHmacAlgSHA224
case .SHA256:
result = kCCHmacAlgSHA256
case .SHA384:
result = kCCHmacAlgSHA384
case .SHA512:
result = kCCHmacAlgSHA512
}
return CCHmacAlgorithm(result)
}
func digestLength() -> Int {
var result: CInt = 0
switch self {
case .MD5:
result = CC_MD5_DIGEST_LENGTH
case .SHA1:
result = CC_SHA1_DIGEST_LENGTH
case .SHA224:
result = CC_SHA224_DIGEST_LENGTH
case .SHA256:
result = CC_SHA256_DIGEST_LENGTH
case .SHA384:
result = CC_SHA384_DIGEST_LENGTH
case .SHA512:
result = CC_SHA512_DIGEST_LENGTH
}
return Int(result)
}
}
extension String {
func digest(algorithm: HMACAlgorithm, key: String) -> String! {
let str = self.cString(using: String.Encoding.utf8)
let strLen = UInt(self.lengthOfBytes(using: String.Encoding.utf8))
let digestLen = algorithm.digestLength()
let result = UnsafeMutablePointer<CUnsignedChar>.allocate(capacity: digestLen)
let keyStr = key.cString(using: String.Encoding.utf8)
let keyLen = UInt(key.lengthOfBytes(using: String.Encoding.utf8))
CCHmac(algorithm.toCCEnum(), keyStr!, Int(keyLen), str!, Int(strLen), result)
let hash = NSMutableString()
for i in 0..<digestLen {
hash.appendFormat("%02x", result[i])
}
result.deinitialize()
return String(hash)
}
}
此外,我在应用程序中有2个秘密通过SSL向服务器发出一些请求。其中一个秘密只是实际秘密的一部分。用户注册时会附加一些信息。我需要在itunes connect的输出合规性中输入什么?
注意:我将在荷兰,比利时,德国和英国销售我的应用程序。
我是对的吗?我害怕回答错误,因为我不想遇到麻烦等等。