Skip to content

Instantly share code, notes, and snippets.

@nimdraugsael
Forked from thibautsacreste/uid.rb
Created October 1, 2013 11:31
Show Gist options
  • Save nimdraugsael/6777112 to your computer and use it in GitHub Desktop.
Save nimdraugsael/6777112 to your computer and use it in GitHub Desktop.
require 'base64'
// Decoding
cookie_value = 'CjpqE0+NhreIpEqgAyz3Ag=='
uid_hex_string = "uscc=" + Base64.decode64(cookie_value).unpack("VVVV").map{|x|x.to_s(16).rjust(8, '0')}.join.upcase
// Encoding with ruby > 1.9.2
uscc = "136A3A0AB7868D4FA04AA48802F72C03"
cookie_value = Base64.safe_encode64(uscc.scan(/.{8}/).map{|x| x.to_i(16)}.pack("VVVV"))
// Encoding with ruby 1.8 + Rails
cookie_value = Base64.encode64s(uscc.scan(/.{8}/).map{|x| x.to_i(16)}.pack("VVVV"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment