How to create a md5 hash of a string in C?

前端 未结 6 842
独厮守ぢ
独厮守ぢ 2020-12-07 19:06

I\'ve found some md5 code that consists of the following prototypes...

I\'ve been trying to find out where I have to put the string I want to hash, what functions I

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 19:25

    It would appear that you should

    • Create a struct MD5context and pass it to MD5Init to get it into a proper starting condition
    • Call MD5Update with the context and your data
    • Call MD5Final to get the resulting hash

    These three functions and the structure definition make a nice abstract interface to the hash algorithm. I'm not sure why you were shown the core transform function in that header as you probably shouldn't interact with it directly.

    The author could have done a little more implementation hiding by making the structure an abstract type, but then you would have been forced to allocate the structure on the heap every time (as opposed to now where you can put it on the stack if you so desire).

提交回复
热议问题