# MD5 16 octet - how to compute?

**URL:** <https://www.ruby-forum.com/t/md5-16-octet-how-to-compute/187155>\
**Category:** Ruby\
**Created:** [April 18, 2010, 8:26pm UTC](https://www.ruby-forum.com/t/md5-16-octet-how-to-compute/187155 "2010-04-18T20:26:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shuaib85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@shuaib85](https://www.ruby-forum.com/u/shuaib85)\
**Post date:** [April 18, 2010, 8:26pm UTC](https://www.ruby-forum.com/t/md5-16-octet-how-to-compute/187155/1 "2010-04-18T20:26:36Z")

</div>

Hi there

I am trying to compute the 16 octet MD5 hash.  
I looked in the digest/md5 and i could not figure it out.  
i used Digest::MD5.hexdigest(value)  
but this computes 32 if I am not mistaken.

Any idea please?

---

<div class="post-metadata">

**Author:** ![shuaib85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@shuaib85](https://www.ruby-forum.com/u/shuaib85)\
**Post date:** [April 18, 2010, 11:27pm UTC](https://www.ruby-forum.com/t/md5-16-octet-how-to-compute/187155/2 "2010-04-18T23:27:07Z")

</div>

Michael F. wrote:

> MD5 computes a 128bit hash.  
> If you use MD5.hexdigest, you will get a String representation in base  
> 16, so it’s 32 octets.  
> You could use MD5.digest instead, which returns a String in base 255,  
> that means it’s 16 octets.

Michael thank you very much, you saved me a lot of time. It took me  
hours to find this out and now my application is working

thanks a lot

---

<div class="post-metadata">

**Author:** ![shuaib85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@shuaib85](https://www.ruby-forum.com/u/shuaib85)\
**Post date:** [April 18, 2010, 11:17pm UTC](https://www.ruby-forum.com/t/md5-16-octet-how-to-compute/187155/3 "2010-04-18T23:17:05Z")

</div>

On Mon, Apr 19, 2010 at 3:26 AM, Shuaib Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi there
> 
> I am trying to compute the 16 octet MD5 hash.  
> I looked in the digest/md5 and i could not figure it out.  
> i used Digest::MD5.hexdigest(value)  
> but this computes 32 if I am not mistaken.
> 
> Any idea please?

MD5 computes a 128bit hash.  
If you use MD5.hexdigest, you will get a String representation in base  
16, so it’s 32 octets.  
You could use MD5.digest instead, which returns a String in base 255,  
that means it’s 16 octets.
