O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The crypto package contains implementations of well-known hash functions. The MD5 hash function is located in the crypto/md5 package. Each hash function in the crypto package implements the Hash interface.  Note that Hash contains the Write  method. With the Write method, it can be utilized as a Writer. This can be seen in the FileMD5 function. The Sum method of Hash accepts the argument of byte slice, where the resulting hash should be placed.

Beware of this. The Sum method does not compute the hash of the argument, but computes the hash into an argument.

On the other hand, md5.Sum, the package function, can be used to produce the hash directly. In this case, the argument of the Sum function is the one from the hash values ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required