擅长:python、mysql、java
<p>我需要这样做来解码从Mongodb转储的BASE64 UUID。最初这块地是猫鼬创造的。基于@tpatja的代码,我使用的代码如下:</p>
<pre class="lang-py prettyprint-override"><code>def base64ToGUID(b64str):
try:
bytes=base64.urlsafe_b64decode(b64str)
except Exception as e:
print("Can't decode base64 ", e)
s = bitstring.BitArray(bytes).hex
return "-".join([s[:8],s[8:][:4],s[12:][:4],s[16:][:4],s[20:]])
</code></pre>