我有一段C#代码,可以将字符串进行编码并返回URL安全的字符串(稍后可以解码)。
string stringToEncrypt = "Winter is coming";
byte[] bytes = new byte[stringToEncrypt.Length * sizeof(char)];
System.Buffer.BlockCopy(stringToEncrypt.ToCharArray(), 0, bytes, 0, bytes.Length);
System.Web.HttpServerUtility.UrlTokenEncode(bytes).Dump();
Dump
来源于LinqPad,我用它来快速测试C#代码片段。
执行该程序返回VwBpAG4AdABlAHIAIABpAHMAIABjAG8AbQBpAG4AZwA1
。
现在,我正在尝试从Clojure服务中完成相同的操作。使用encode
库,并参考这个答案。当我有
(String. (b64/encode (.getBytes email)) "UTF-8")
我得到了
V2ludGVyIGlzIGNvbWluZw==
,它:
- 没有进行URL编码
- 与C#版本不匹配。
UrlTokenEncode()
,但是它没有详细说明其实现方式,无法确定内部发生了什么。我能否在Clojure中生成等效字符串?