Md5 hashing function


(Carmelo Allegra) #1

I’m new at Golang and programming in general and this might be a little over my capabilities, but anyway.

I’m trying to implement a function that starting form a video file,
would return the md5 hash composed by taking the first and the last 64kb of the video file,
putting all together and generating a md5 of the resulting data (128kb).

I have put together with the help of Google the md5 hash function, what I am struggling to realize
is how to “take” the first and last 64Kb of the file and then “join” together these pieces.

On a Discord golang group I have been hinted to look at the Seek() function on the os package :

func main() {
testFile := os.Args[1]
var offset int64 = 64 * 1024 //64Kb
var whence int = 0           //starting from the beginning of the file
file, err := os.Open(testFile)
if err != nil {
	fmt.Println(err)
}

newPosition, err := file.Seek(offset, whence)
if err != nil {
	fmt.Println(err)
}

fmt.Println("Moved to new position: ", newPosition)

newPosition returns an int64, do I write to a new writer?

Thanks in advance