title: Swift 3 making sha1, sha256 and md5 functions
body: <p>In Swift 2, I used the following code to extend string variables and to be able to make sha1, sha256, and md5.</p>
  
  <p>After moving to swift 3, the code is not working any more! I tried to convert it but run into continuous errors.</p>
  
  <p>Any idea how can I solve this?</p>
  
  <pre><code>extension NSData {
      func hexString() -&gt; String {
          var string = String()
          for i in UnsafeBufferPointer&lt;UInt8&gt;(start: UnsafeMutablePointer&lt;UInt8&gt;(bytes), count: length) {
              string += Int(i).hexString()
          }
          return string
      }
  
      func MD5() -&gt; NSData {
          let result = NSMutableData(length: Int(CC_MD5_DIGEST_LENGTH))!
          CC_MD5(bytes, CC_LONG(length), UnsafeMutablePointer&lt;UInt8&gt;(result.mutableBytes))
          return NSData(data: result)
      }
  
      func SHA1() -&gt; NSData {
          let result = NSMutableData(length: Int(CC_SHA1_DIGEST_LENGTH))!
          CC_SHA1(bytes, CC_LONG(length), UnsafeMutablePointer&lt;UInt8&gt;(result.mutableBytes))
          return NSData(data: result)
      }
  
      func SHA256() -&gt; NSData {
          let result = NSMutableData(length: Int(CC_SHA256_DIGEST_LENGTH))
          CC_SHA256(bytes, CC_LONG(length), UnsafeMutablePointer(result!.mutableBytes))
          return NSData(data: result!)
      }
  }
  
  extension String {
      func hexString() -&gt; String {
          return (self as NSString).dataUsingEncoding(NSUTF8StringEncoding)!.hexString()
      }
  
      func MD5() -&gt; String {
          return (self as NSString).dataUsingEncoding(NSUTF8StringEncoding)!.MD5().hexString()
      }
  
      func SHA1() -&gt; String {
          return (self as NSString).dataUsingEncoding(NSUTF8StringEncoding)!.SHA1().hexString()
      }
  
      func SHA256() -&gt; String {
          return (self as NSString).dataUsingEncoding(NSUTF8StringEncoding)!.SHA256().hexString()
      }
  
  }
  </code></pre>