Skip to content

Latest commit

 

History

History
43 lines (35 loc) · 1.35 KB

README.md

File metadata and controls

43 lines (35 loc) · 1.35 KB

sha1-swift

What?

An SHA-1 hash implementation in Swift

Usage

  1. Include SHA1.swift in your project
  2. Call a public method:
let hash:String = SHA1.hexString(fromFile: filename)

returns Optional("84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1")

let hash:[Int] = SHA1.hash(fromFile: filename)

returns Optional([2845392438, 1191608682, 3124634993, 2018558572, 2630932637])

let hash = SHA1.hexString(from: "abc")

returns Optional("A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D")

let hash = SHA1.hexString(from: data)

returns Optional("A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D")

Implementation details

  • Implemented as a struct with static methods in order to avoid garbage like
let my_sha1_calculator=SHA1()
my_sha1_calculator.hashFromFile(myfile)
  • Since Swift lacks bignums, the hash digest is returned as either a hexadecimal string or as an array of five ints.

Resources

Check out as well