title: How to use common crypto and/or calculate sha256 in swift 2 & 3
body: <p>I am trying to make hash a password value according to sha256. I already search this but there is no info about swift 2. This solution did not worked for me </p>
  
  <pre><code>func sha256(data:String) -&gt; String {
          let data = self.dataUsingEncoding(NSUTF8StringEncoding)!
          var digest = [UInt8](count:Int(CC_SHA256_DIGEST_LENGTH), repeatedValue: 0)
          CC_SHA256(data.bytes, CC_LONG(data.length), &amp;digest)
          let hexBytes = digest.map { String(format: "%02hhx", $0) }
          return hexBytes.joinWithSeparator("")
      }
  </code></pre>
  
  <p>It gives error: Use of unresolved identifier CC_SHA256_DIGEST_LENGTH</p>