[英]Decrypt byte data in javascript/Jquery
我有一個項目,我在.cs文件中使用gzip壓縮數據並在html頁面中獲取它。 這是我的gzip代碼。
public byte[] CustomerList()
{
SqlDataAdapter da = new SqlDataAdapter("select CustomerID from CustomerMaster", con);
DataSet ds = new DataSet();
da.Fill(ds);
return CompressData(ds);
}
public byte[] CompressData(DataSet ds)
{
using (MemoryStream memory = new MemoryStream())
{
using (GZipStream gzip = new GZipStream(memory, CompressionMode.Compress))
{
var formatter = new BinaryFormatter();
formatter.Serialize(gzip, ds);
gzip.Close();
}
return memory.ToArray();
}
}
我使用ajax函數成功地從html頁面接收了數據。 這是我的代碼
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
url: "Service1.svc/CustomerList",
contentType: "application/json; charset=utf-8",
dataType: "json",
processdata: true,
success: function (data) {
alert(data.CustomerListResult);
},
error: function () {
alert("Error");
}
});
});
</script>
我收到了字節格式的數據。 現在我想解密字節數據以獲得原始數據。 在這里我卡住了。 請幫助我如何解密字節以獲取原始數據。
最好的解決方案是不壓縮數據,而是在Web服務器上啟用壓縮。 如果必須預壓縮數據,則需要在另一端將其解壓縮(這不是世界上最快的事情)。 我不懂C#,但看起來您正在使用標准gzip; 因此,您必須編寫自己的gzip庫或查找以前已經制作的gzip庫。 一個快速的Google發現了這一點 :它用於node.js,但是您可能可以移植它以在瀏覽器中使用。
tl; dr讓您的Web服務器壓縮數據,而不是自己處理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.