Skip to content

Instantly share code, notes, and snippets.

@bendiksolheim
Created November 18, 2021 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendiksolheim/7128f5ccec78b01935c9033194cf06ce to your computer and use it in GitHub Desktop.
Save bendiksolheim/7128f5ccec78b01935c9033194cf06ce to your computer and use it in GitHub Desktop.
import ArgumentParser
import Crypto
struct Hsh: ParsableCommand {
static var configuration = CommandConfiguration(
subcommands: [Md5.self, Sha1.self]
)
}
struct Md5: ParsableCommand {
@Argument(help: "String to calculate MD5 hash from")
var value: String
mutating func run() {
let data = value.data(using: .utf8)
let hash = Insecure.MD5.hash(data: data!)
print(hash.map { String(format: "%02hhx", $0) }.joined())
}
}
struct Sha1: ParsableCommand {
@Argument(help: "String to calculate Sha1 hash from")
var value: String
mutating func run() {
let data = value.data(using: .utf8)
let hash = Insecure.SHA1.hash(data: data!)
print(hash.map { String(format: "%02hhx", $0) }.joined())
}
}
Hsh.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment