怎麼實現Web系統URL傳輸 表單提交 引數加密

2021-03-31 23:47:44 字數 2086 閱讀 2583

網上很多人在問怎麼實現web系統url傳輸(表單提交)引數加密。例如:要進行乙個使用者帳號編輯,要傳遞使用者的id,url如下:http://localhost/mysystem/editaccounts.aspx?id=2

但又不想讓別人知道這個使用者的id為2,惡意的使用者可能還會將2修改,改為別的使用者id。

加密傳遞的引數值可以解決問題。

以下是自己寫的dec加密、解密的基類。

檔名:security.cs

using system;

using system.security.cryptography;

using system.io;

using system.text;

public security()

///

/// 加密url傳輸的字串

///

///

///

public string encryptquerystring(string querystring)

///

/// 解密url傳輸的字串

///

///

///

public string decryptquerystring(string querystring)

///

/// 加密帳號口令

///

///

///

public string encryptpassword(string password)

///

/// 解密帳號口令

///

///

///

public string decryptpassword(string password)

///

/// dec 加密過程

///

///

///

///

public string encrypt(string ptoencrypt,string skey) 

des.key = asciiencoding.ascii.getbytes(skey);  //建立加密物件的金鑰和偏移量,此值重要,不能修改 

des.iv  = asciiencoding.ascii.getbytes(skey); 

memorystream ms = new memorystream(); 

cryptostream cs = new cryptostream(ms, des.createdecryptor(),cryptostreammode.write); 

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

cs.flushfinalblock(); 

stringbuilder ret = new stringbuilder();  //建立stringbuild物件,createdecrypt使用的是流物件,必須把解密後的文字變成流物件 

return system.text.encoding.default.getstring(ms.toarray()); 

} ///

/// 檢查己加密的字串是否與原文相同

///

///

///

///

///

public bool validatestring(string enstring, string fostring, int mode)

else

case 2:

if (decrypt(enstring,_passwordkey) == fostring.tostring())

else}}

}}

類中url及帳號加密使用了不同的key。呼叫url加密過程如下:

eip.framework.security objsecurity = new eip.framework.security();

objsecurity.encryptquerystring(''待加密的字串'');

解密:objsecurity.decryptquerystring(''傳遞過來的引數);

怎麼實現Web系統URL傳輸 表單提交 引數加密

網上很多人在問怎麼實現web系統url傳輸 表單提交 引數加密。例如 要進行乙個使用者帳號編輯,要傳遞使用者的id,url如下 http localhost mysystem editaccounts.aspx?id 2 但又不想讓別人知道這個使用者的id為2,惡意的使用者可能還會將2修改,改為別的...

短 URL 系統是怎麼設計的?

tang minyi 的回答,也非常不錯,如果面試者這麼回答,我也會很高興的。對於我用詞比較激烈的問題,我面試時真實想法既是如此,也懶得潤色了。這個問題看到就想答。而這個問題,也是我現在招聘面試題裡面必考的一道,這一道題裡面有很多可考的地方,能夠相對綜合的考察候選人的功力。最爛的回答實現乙個演算法,...

TCP是怎麼實現可靠傳輸的

tcp協議傳輸的特點主要是面向位元組流 傳輸可靠 面向連線。答 tcp協議保證資料傳輸可靠性的方式主要有 序列號 tcp傳輸時將每個位元組的資料都進行了編號,即序列號。確認應答 tcp傳輸過程中,每次接收方收到資料後,都會對傳輸方進行確認應答。也就是傳送ack報文。這個ack報文當中帶有對應的確認序...