簡體   English   中英

解密MVC中的數據?

[英]decrypt data in view in MVC?

在MVC4中,我創建了Edit函數並將數據傳遞給View from Controller,但數據已加密。 在View中顯示數據時,我不知道如何解密數據。

在此輸入圖像描述

public static string setEncrypt_Account(string sParam)
        {
            sParam = Core_App.RijndaelSimple.Encrypt(sParam, "pr@se_AccPwd", "cts@devteam", "MD5", 2, "@1B2c3D4e5F6g7H8", 256);
            return sParam;
        }
        public static string getDecrypt_Account(string sParam)
        {
            sParam = Core_App.RijndaelSimple.Decrypt(sParam, "pr@se_AccPwd", "cts@devteam", "MD5", 2, "@1B2c3D4e5F6g7H8", 256);
            return sParam;
        }

您應該在edit(get)操作上調用getDecrypt_Account(string sParam)來解密數據,然后傳遞給視圖。 就像是:

@using Your.Decrypt.Method.Path;

[HttpGet]
public ActionResult Edit(int id)
{
    User user = new Repository().GetUser(id);

    return View(new EditViewModel()
    {
        Code = user.Code,
        UserName = getDecrypt_Account(user.UserName),
        FullName = user.FullName
    });
}

我希望你明白這個主意。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM