Server.UrlEncode 关于这个用法问题。
Response.Write("<script language=javascript>window.open('Default.aspx?id='+'"+str+"');</script>");我用这种方式打开一个网页,想把传的值进行加密,我想用 Server.UrlEncode 请问怎么用啊。 --------------------编程问答-------------------- Server.UrlEncode并不能进行加密.
--------------------编程问答-------------------- 那怎么进行加密啊。 --------------------编程问答-------------------- 网上现成的
using System;
using System.Web;
using System.Web.UI;
using System.IO;
using System.Security;
using System.Security.Cryptography;
using System.Configuration;
public class DataProtection
{
public static RSACryptoServiceProvider rsa;
public static void AssignParameter()
{
const int PROVIDER_RSA_FULL = 1;
const string CONTAINER_NAME = "NMTechnology";
CspParameters cspParams;
cspParams = new CspParameters(PROVIDER_RSA_FULL);
cspParams.KeyContainerName = CONTAINER_NAME;
cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
cspParams.ProviderName = "Microsoft Strong Cryptographic Provider";
try
{
rsa = new RSACryptoServiceProvider(cspParams);
}
catch
{
string x = "X";
}
}
public static string Encrypt(string data2Encrypt)
{
AssignParameter();
StreamReader reader = new
StreamReader(ConfigurationManager.AppSettings["PublicKey"].ToString());
string publicOnlyKeyXML = reader.ReadToEnd();
rsa.FromXmlString(publicOnlyKeyXML);
reader.Close();
//read plaintext, encrypt it to ciphertext
byte[] plainbytes = System.Text.Encoding.UTF8.GetBytes(data2Encrypt);
byte[] cipherbytes = rsa.Encrypt(plainbytes, false);
return Convert.ToBase64String(cipherbytes);
}
public static void AssignNewKey()
{
AssignParameter();
//provide public and private RSA params
StreamWriter writer = new
StreamWriter(ConfigurationManager.AppSettings["PrivateKey"].ToString());
string publicPrivateKeyXML = rsa.ToXmlString(true);
writer.Write(publicPrivateKeyXML);
writer.Close();
//provide public only RSA params
writer = new
StreamWriter(ConfigurationManager.AppSettings["PublicKey"].ToString());
string publicOnlyKeyXML = rsa.ToXmlString(false);
writer.Write(publicOnlyKeyXML);
writer.Close();
}
public static string Decrypt(string data2Decrypt)
{
AssignParameter();
byte[] getpassword = Convert.FromBase64String(data2Decrypt);
StreamReader reader = new
StreamReader(ConfigurationManager.AppSettings["PrivateKey"].ToString());
string publicPrivateKeyXML = reader.ReadToEnd();
rsa.FromXmlString(publicPrivateKeyXML);
reader.Close();
//read ciphertext, decrypt it to plaintext
byte[] plain = rsa.Decrypt(getpassword, false);
return System.Text.Encoding.UTF8.GetString(plain);
}
}
--------------------编程问答-------------------- 用DES或SHA加密后再传..UrlEncode 只是变成相应ASCII码 --------------------编程问答-------------------- UrlEncode和UrlDecode是用来转换字符码的.传的值如果是汉字一般用的比较多
如果要加密就得用慕白兄说的方法 --------------------编程问答-------------------- 学习中
补充:.NET技术 , ASP.NET