def MD5hex2base64(str) h1=[].clear # split the 32 byte hex into a 16 byte array 16.times{ h1.push(str.slice!(0,2).hex) } # pack (C* = unsigned char), (m = base64 encoded output) [h1.pack("C*")].pack("m") end