用RSA實現Web單點登入密碼的加密傳輸

來源:互聯網
上載者:User

標籤:style   blog   class   code   java   ext   

在使用通用許可權管理系統(吉日嘎拉)的單點登入功能時,對登入密碼使用了RSA加密(非對稱式加密),有使用這個許可權管理系統的可參考下。

 

前端部分,請引用以下幾個js檔案:

<script type="text/javascript" src="ExtJS/jquery.js"></script><script type="text/javascript" src="ExtJS/BigInt.js" ></script><script type="text/javascript" src="ExtJS/RSA.js"></script><script type="text/javascript" src="ExtJS/Barrett.js"></script>

 下載:http://files.cnblogs.com/hnsongbiao/ExtJS.zip

登入頁面前端主要代碼:

setMaxDigits(129);var key = new RSAKeyPair("<%=strPublicKeyExponent%>", "", "<%=strPublicKeyModulus%>");var password = document.getElementById("password");var pwd = encryptedString(key, password.value);

 


後台主要功能代碼:

 

RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();Session["private_key"] = rsa.ToXmlString(true);RSAParameters parameter = rsa.ExportParameters(true);strPublicKeyExponent = BytesToHexString(parameter.Exponent);strPublicKeyModulus = BytesToHexString(parameter.Modulus);    。。。。。。rsa.FromXmlString((string)Session["private_key"]);byte[] results = rsa.Decrypt(HexStringToBytes(password), false);System.Text.ASCIIEncoding enc = new ASCIIEncoding();password = enc.GetString(results);

 

 

 

 

下面可以看到傳輸時密碼已經經過RSA非對稱式加密了(我這裡同時進行了對稱式加密)

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.