實現URL引數的加密和解密的方法

2021-06-01 20:04:52 字數 3016 閱讀 8359

1、post/get  這個不用多說了。

2、 encrypting   querystrings   with   .net

code:

c#:

using system;

using system.io;

using system.xml;

using system.text;

using system.security.cryptography;

public class encryption64

...;

//private byte iv = ; // it can be any byte value

public static string decrypt(string stringtodecrypt,

string sencryptionkey)

...;

byte iv = ...;

byte inputbytearray = new byte[stringtodecrypt.length];

try...

catch (system.exception ex)

...}

public static string encrypt(string stringtoencrypt,

string sencryptionkey)

...;

byte iv = ...;

byte inputbytearray;

try...

catch (system.exception ex)

...}

}

vb.net

imports system

imports system.io

imports system.xml

imports system.text

imports system.security.cryptography

public class encryption64

private key() as byte = {}

private iv() as byte =

public function decrypt(byval stringtodecrypt as string, _

byval sencryptionkey as string) as string

dim inputbytearray(stringtodecrypt.length) as byte

trykey = system.text.encoding.utf8.getbytes(left(sencryptionkey, 8))

dim des as new descryptoserviceprovider()

inputbytearray = convert.frombase64string(stringtodecrypt)

dim ms as new memorystream()

dim cs as new cryptostream(ms, des.createdecryptor(key, iv), _

cryptostreammode.write)

cs.write(inputbytearray, 0, inputbytearray.length)

cs.flushfinalblock()

dim encoding as system.text.encoding = system.text.encoding.utf8

return encoding.getstring(ms.toarray())

catch e as exception

return e.message

end try

end function

public function encrypt(byval stringtoencrypt as string, _

byval sencryptionkey as string) as string

trykey = system.text.encoding.utf8.getbytes(left(sencryptionkey, 8))

dim des as new descryptoserviceprovider()

dim inputbytearray() as byte = encoding.utf8.getbytes( _

stringtoencrypt)

dim ms as new memorystream()

dim cs as new cryptostream(ms, des.createencryptor(key, iv), _

cryptostreammode.write)

cs.write(inputbytearray, 0, inputbytearray.length)

cs.flushfinalblock()

return convert.tobase64string(ms.toarray())

catch e as exception

return e.message

end try

end function

end class

default.aspx.cs

//加密url

protected void page_load(object sender, eventargs e)

...public string encryptquerystring(string strquerystring)

...

default2.aspx.cs

//解密url

protected void page_load(object sender, eventargs e)

...}

public string decryptquerystring(string strquerystring)

...

對Url傳輸引數進行加密和解密

最近做乙個論壇入口時要實現帳號和密碼不在ie位址列出現而做的 index.aspx.cs 加密處理 byte iv64 byte bykey64 public string encrypt string strtext catch exception ex private void btnlogin...

對Url傳輸引數進行加密和解密

最近做乙個論壇入口時要實現帳號和密碼不在ie位址列出現而做的 index.aspx.cs 加密處理 byteiv64 bytebykey64 public stringencrypt stringstrtext catch exceptionex private voidbtnlogin click...

檔案加密解密 URl引數加密解密

sliverlight 加密解密 public static class encryption endregion region silverlight密碼解密 解密資料 加密後的字串 加密前的字串 public static string decrypt string input endregio...