急急急!我需要编码与解码函数,加解密也行

yuesongboy 2007-04-07 09:07:47
我在javascript中加密一段字符串,然后在服务器端代码中解密这个字符串
...全文
258 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangzhaoli1982 2007-04-07
  • 打赏
  • 举报
回复



public static void Encrypt(string strMsgIn, out string strEncrypted)
{
strEncrypted = "";


byte[] pByteKey = {0xEF, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12};
byte[] pByteIV = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};


byte[] pByte = System.Text.Encoding.UTF8.GetBytes(strMsgIn);

System.IO.MemoryStream pMemoryStream = new System.IO.MemoryStream();


System.Security.Cryptography.DESCryptoServiceProvider pDESCryptoServiceProvider
= new System.Security.Cryptography.DESCryptoServiceProvider();

System.Security.Cryptography.ICryptoTransform pICryptoTransform = pDESCryptoServiceProvider.CreateEncryptor(pByteKey,pByteIV);


System.Security.Cryptography.CryptoStream pCryptoStream =
new System.Security.Cryptography.CryptoStream(pMemoryStream,pICryptoTransform,System.Security.Cryptography.CryptoStreamMode.Write);


pCryptoStream.Write(pByte, 0, pByte.Length);
pCryptoStream.FlushFinalBlock();

strEncrypted = System.Convert.ToBase64String(pMemoryStream.ToArray());


}


public static void Decrypt(string strEncryptedMsg, out string strDecrypted)
{
strDecrypted = "";


byte[] pByteKey = {0xEF, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12};
byte[] pByteIV = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};

byte[] pByte = System.Convert.FromBase64String(strEncryptedMsg);


System.IO.MemoryStream pMemoryStream = new System.IO.MemoryStream();


System.Security.Cryptography.DESCryptoServiceProvider pDESCryptoServiceProvider
= new System.Security.Cryptography.DESCryptoServiceProvider();

System.Security.Cryptography.ICryptoTransform pICryptoTransform = pDESCryptoServiceProvider.CreateDecryptor(pByteKey,pByteIV);


System.Security.Cryptography.CryptoStream pCryptoStream =
new System.Security.Cryptography.CryptoStream(pMemoryStream,pICryptoTransform,System.Security.Cryptography.CryptoStreamMode.Write);


pCryptoStream.Write(pByte, 0, pByte.Length);
pCryptoStream.FlushFinalBlock();

strDecrypted = System.Text.Encoding.UTF8.GetString(pMemoryStream.ToArray());



}
yuesongboy 2007-04-07
  • 打赏
  • 举报
回复
怎么少了最后两个字符串?
cpp2017 2007-04-07
  • 打赏
  • 举报
回复
protected void Page_Load(object sender, EventArgs e) { Response.Write(this.xor("FWAF", "2")); } protected string xor(string str,string sKey) { string res = ""; for (int i = 0; i < str.Length; i++) { res += ((char)(((int) str.Substring(i, 1).ToCharArray()[0]) ^ ((int) sKey.Substring(i % sKey.Length).ToCharArray()[0]))).ToString(); } return res; }
cpp2017 2007-04-07
  • 打赏
  • 举报
回复
<script type="text/javascript" > function String.prototype.xor(key) //异或操作,也就是通用的对称加密、解密操作 { var result = ""; for (var i=0; i<this.length; i++) result += String.fromCharCode(this.charCodeAt(i)^key.charCodeAt(i%key.length)); return result; } var str = "test"; alert(str.xor("2")) </script>
yuesongboy 2007-04-07
  • 打赏
  • 举报
回复
@hertcloud(·£孙子兵法£·)
我不能用你的方法,不能达到我的要求,如果只要对字符串处理就行了,编码加密还是什么无所谓
然后在服务器端还原就可以了.
nmcfwhl1 2007-04-07
  • 打赏
  • 举报
回复
其实没有必要加密的。加密是可以。但是它会增加系统的不稳定。因为IE在解析的时候会理解错你加密后的代码
hertcloud 2007-04-07
  • 打赏
  • 举报
回复
javascript的escape函数进行转义

.cs


HttpUtility.UrlDecode()




yuesongboy 2007-04-07
  • 打赏
  • 举报
回复
高手去哪儿了???
yuesongboy 2007-04-07
  • 打赏
  • 举报
回复
客户端javascript函数加密

服务器端代码函数解密
amao110 2007-04-07
  • 打赏
  • 举报
回复
Dim md5Hasher As New MD5CryptoServiceProvider
Dim hashedDataBytes As Byte()
Dim encoder As New UTF8Encoding
hashedDataBytes = md5Hasher.ComputeHash(encoder.GetBytes(TextBox2.Text))
yuesongboy 2007-04-07
  • 打赏
  • 举报
回复
加密编码都行啊,
cpp2017 2007-04-07
  • 打赏
  • 举报
回复
是要加密还是编码?
fxqyyzg 2007-04-07
  • 打赏
  • 举报
回复
URL编码: bodyEncode.value = encodeURI(document.all.keyword.value)

URL解码: body.value = decodeURI(bodyEncode.value)

---------
你是问这个?
yuesongboy 2007-04-07
  • 打赏
  • 举报
回复
我需要在客户端javascript调用javascript加密方法加密字符串,然后用服务器代码解密字符串,

谢谢
孟子E章 2007-04-07
  • 打赏
  • 举报
回复
你这样问是不行的。客户端怎么加密的?

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧