Answers for "sha256 encryption generator"

2

swift sha256 encryption

extension String {

    func sha256() -> String{
        if let stringData = self.data(using: String.Encoding.utf8) {
            return hexStringFromData(input: digest(input: stringData as NSData))
        }
        return ""
    }

    private func digest(input : NSData) -> NSData {
        let digestLength = Int(CC_SHA256_DIGEST_LENGTH)
        var hash = [UInt8](repeating: 0, count: digestLength)
        CC_SHA256(input.bytes, UInt32(input.length), &hash)
        return NSData(bytes: hash, length: digestLength)
    }

    private  func hexStringFromData(input: NSData) -> String {
        var bytes = [UInt8](repeating: 0, count: input.length)
        input.getBytes(&bytes, length: input.length)

        var hexString = ""
        for byte in bytes {
            hexString += String(format:"%02x", UInt8(byte))
        }

        return hexString
    }

}
Posted by: Guest on March-04-2020
0

sha256 decrypt

A hash function cannot be 'decrypted', but a rainbowtable 
can be used to try and find a plaintext match. Still, 
that doesn't guarentee a match.
Posted by: Guest on September-20-2021

Code answers related to "Swift"

Browse Popular Code Answers by Language