Skip to content

Instantly share code, notes, and snippets.

@bendiksolheim
Created Nov 18, 2021
Embed
What would you like to do?
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