# Nginx uid decoding using Base64.decode64

**URL:** <https://www.ruby-forum.com/t/nginx-uid-decoding-using-base64-decode64/211651>\
**Category:** NGINX\
**Created:** [September 9, 2011, 7:35pm UTC](https://www.ruby-forum.com/t/nginx-uid-decoding-using-base64-decode64/211651 "2011-09-09T19:35:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [September 9, 2011, 7:35pm UTC](https://www.ruby-forum.com/t/nginx-uid-decoding-using-base64-decode64/211651/1 "2011-09-09T19:35:20Z")

</div>

Hi,  
I was facing a problem while decoding a nginx generated uid using  
ruby.

The uid which I get from nginx cookie is “CqCx7E5qMNUxrmAUAwMJAg==” and  
when I try to decode this using  
Base64.decode64(“CqCx7E5qMNUxrmAUAwMJAg==”) , it gives me  
“\n\xA0\xB1\xECNj0\xD51\xAE`\x14\x03\x03\t\x02” instead of  
“ECB1A00AD5306A4E1460AE3102090303” which I see in my access  
logs($uid\_got value).

can any one give some suggestions on this issue?

---

<div class="post-metadata">

**Author:** ![dhaval\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@dhaval\_d](https://www.ruby-forum.com/u/dhaval_d)\
**Post date:** [September 9, 2011, 8:11pm UTC](https://www.ruby-forum.com/t/nginx-uid-decoding-using-base64-decode64/211651/2 "2011-09-09T20:11:48Z")

</div>

Hello!

On Fri, Sep 09, 2011 at 07:35:20PM +0200, dhaval d. wrote:

> can any one give some suggestions on this issue?

Logged value is a hex representation of the data, using 4 host-order  
uint32\_t values. I.e. “\n\xA0\xB1\xEC” matches “ECB1A00A” and so on.

Maxim D.

---

<div class="post-metadata">

**Author:** ![dhaval\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@dhaval\_d](https://www.ruby-forum.com/u/dhaval_d)\
**Post date:** [September 9, 2011, 10:33pm UTC](https://www.ruby-forum.com/t/nginx-uid-decoding-using-base64-decode64/211651/3 "2011-09-09T22:33:58Z")

</div>

Hello Maxim,  
Thanks a lot for your reply. Because of which I was able to  
figure out the way to decode it. Here is the snippet for those who wants  
to know.

cookie = “CqCx7E5qMNUxrmAUAwMJAg==”

Base64.decode64(cookie).unpack(“L\*”).collect{|num|  
num.to\_s(16)}.join("").upcase
