Skip to content

Instantly share code, notes, and snippets.

@ohodoa
Created March 25, 2015 06:44
Show Gist options
  • Save ohodoa/0f06c9ae835c0b21f5fb to your computer and use it in GitHub Desktop.
Save ohodoa/0f06c9ae835c0b21f5fb to your computer and use it in GitHub Desktop.
golang md5 file
package main
import (
"crypto/md5"
"os"
"io"
"log"
"encoding/hex"
)
func main() {
h := md5.New()
f, err := os.Open(os.Args[1])
if err != nil {
log.Fatal(err)
}
defer f.Close()
if _, err := io.Copy(h, f); err != nil {
log.Fatal(err)
}
os.Stdout.WriteString(hex.EncodeToString(h.Sum(nil)))
}
@CypherpunkSamurai
Copy link

Another alternative is to use:

return fmt.Sprintf("%x", md5.Sum([]byte(text)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment