Created
January 6, 2020 07:20
-
-
Save SunXiaoShan/0d8f70339145f349f6908d96c4ee5a6d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 取得 Query 的 body string | |
let dateString = query(dict) //使用預設的 URLEncoding.default 產生Body Encode | |
print(dateString) | |
// 以 sha256 把 key 和 body 作成簽名 | |
let keybytes: Array<UInt8> = input0.text!.bytes | |
let signature = try! HMAC(key: keybytes, variant: .sha256).authenticate(dateString.bytes) | |
print("signature \(signature.toHexString())") | |
// 將簽名跟 key id 放在 Header,傳出去 | |
let headers: HTTPHeaders = [ | |
"x-keyid": inputkeyID.text!, | |
"x-signature":signature.toHexString() | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment