0001 // 0002 // SHA256Hasher.swift 0003 // Vapor 0004 // 0005 // Created by Tanner Nelson on 2/23/16. 0006 // Copyright © 2016 Tanner Nelson. All rights reserved. 0007 // 0008 0009 import Foundation 0010 0011 public class SHA256Hasher: HashDriver { 0012 0013 public func hash(message: String, key: String) -> String { 0014 0015 var msgBuff = [UInt8]() 0016 msgBuff += message.utf8 0017 0018 var keyBuff = [UInt8]() 0019 keyBuff += key.utf8 0020 0021 if let hmac = HMAC.authenticate(key: keyBuff, message: msgBuff) { 0022 return NSData.withBytes(hmac).toHexString() 0023 } else { 0024 Log.error("Unable to create hash, returning hash for empty string.") 0025 return "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" 0026 } 0027 0028 } 0029 0030 }
Hash.swift:26 public static var driver: HashDriver = SHA256Hasher()