asp.net mvc剑道ui网格加密列数据 var grid=$(“#grid”).kendoGrid({ 数据源:数据源, pageable:对, 身高:430, 工具栏:[“创建”], 栏目:[ “产品名称”{ 字段:“ID”, 标题:“产品ID”, 宽度:“100px” }, { 字段:“单价”, 标题:“单价”, 格式:“{0:c}”, 宽度:“100px” }, { 字段:“单位股票”, 标题:“库存单位”, 宽度:“100px” }, { 字段:“中止”, 宽度:“100px” }, { 命令:[“编辑”、“销毁”], 标题:“, 宽度:“172px” } ], 可编辑:“内联” }).数据(“kendoGrid”);

asp.net mvc剑道ui网格加密列数据 var grid=$(“#grid”).kendoGrid({ 数据源:数据源, pageable:对, 身高:430, 工具栏:[“创建”], 栏目:[ “产品名称”{ 字段:“ID”, 标题:“产品ID”, 宽度:“100px” }, { 字段:“单价”, 标题:“单价”, 格式:“{0:c}”, 宽度:“100px” }, { 字段:“单位股票”, 标题:“库存单位”, 宽度:“100px” }, { 字段:“中止”, 宽度:“100px” }, { 命令:[“编辑”、“销毁”], 标题:“, 宽度:“172px” } ], 可编辑:“内联” }).数据(“kendoGrid”);,asp.net,asp.net-mvc,kendo-ui,kendo-asp.net-mvc,kendo-ui-mvc,Asp.net,Asp.net Mvc,Kendo Ui,Kendo Asp.net Mvc,Kendo Ui Mvc,如果用户看不到我的真实ID,我如何在kendo ui网格上加密列产品ID?我正在使用ASP.NETMVC5 谢谢大家! 可以对列使用kendo grid client Template,而不是直接加密,在该列中,您将Id值传递给javascript函数,然后使用您的算法对其进行加密并返回。 差不多 var grid = $("#grid").kendoGrid({ dataSource: dataSource, pageable: true,

如果用户看不到我的真实ID,我如何在kendo ui网格上加密列产品ID?我正在使用ASP.NETMVC5


谢谢大家!

可以对列使用kendo grid client Template,而不是直接加密,在该列中,您将Id值传递给javascript函数,然后使用您的算法对其进行加密并返回。 差不多

var grid = $("#grid").kendoGrid({ dataSource: dataSource, pageable: true, height: 430, toolbar: ["create"], columns: [ "ProductName", { field: "ID", title: "Product ID", width: "100px" }, { field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: "100px" }, { field: "UnitsInStock", title: "Units In Stock", width: "100px" }, { field: "Discontinued", width: "100px" }, { command: ["edit", "destroy"], title: "", width: "172px" } ], editable: "inline" }).data("kendoGrid"); 及


函数加密(id)
{
//加密ID的逻辑
返回encryptedID.toString();
}
如果这只是为了向用户展示,那么这个解决方案是有效的

第二种解决方案是只隐藏列(我的意思是没有必要向用户显示ID)


如果您觉得这有帮助,请在绑定数据后将数据加载到代码中之前,将Enrcypt数据标记为答案

要做到这一点,请使用encrpyt类,如下所示

 <script> 
function Encrypt(id)
{
// Logic to Encrypt ID
return encryptedID.toString();
}
</script>
然后像这样使用它:

public class DataEncryptor
{
    TripleDESCryptoServiceProvider symm;

    #region Factory
    public DataEncryptor()
    {
        this.symm = new TripleDESCryptoServiceProvider();
        this.symm.Padding = PaddingMode.PKCS7;
    }
    public DataEncryptor(TripleDESCryptoServiceProvider keys)
    {
        this.symm = keys;
    }

    public DataEncryptor(byte[] key, byte[] iv)
    {
        this.symm = new TripleDESCryptoServiceProvider();
        this.symm.Padding = PaddingMode.PKCS7;
        this.symm.Key = key;
        this.symm.IV = iv;
    }

    #endregion

    #region Properties
    public TripleDESCryptoServiceProvider Algorithm
    {
        get { return symm; }
        set { symm = value; }
    }
    public byte[] Key
    {
        get { return symm.Key; }
        set { symm.Key = value; }
    }
    public byte[] IV
    {
        get { return symm.IV; }
        set { symm.IV = value; }
    }

    #endregion

    #region Crypto

    public byte[] Encrypt(byte[] data) { return Encrypt(data, data.Length); }
    public byte[] Encrypt(byte[] data, int length)
    {
        try
        {
            // Create a MemoryStream.
            var ms = new MemoryStream();

            // Create a CryptoStream using the MemoryStream 
            // and the passed key and initialization vector (IV).
            var cs = new CryptoStream(ms,
                symm.CreateEncryptor(symm.Key, symm.IV),
                CryptoStreamMode.Write);

            // Write the byte array to the crypto stream and flush it.
            cs.Write(data, 0, length);
            cs.FlushFinalBlock();

            // Get an array of bytes from the 
            // MemoryStream that holds the 
            // encrypted data.
            byte[] ret = ms.ToArray();

            // Close the streams.
            cs.Close();
            ms.Close();

            // Return the encrypted buffer.
            return ret;
        }
        catch (CryptographicException ex)
        {
            Console.WriteLine("A cryptographic error occured: {0}", ex.Message);
        }
        return null;
    }

    public string EncryptString(string text)
    {
        return Convert.ToBase64String(Encrypt(Encoding.UTF8.GetBytes(text)));
    }

    public byte[] Decrypt(byte[] data) { return Decrypt(data, data.Length); }
    public byte[] Decrypt(byte[] data, int length)
    {
        try
        {
            // Create a new MemoryStream using the passed 
            // array of encrypted data.
            MemoryStream ms = new MemoryStream(data);

            // Create a CryptoStream using the MemoryStream 
            // and the passed key and initialization vector (IV).
            CryptoStream cs = new CryptoStream(ms,
                symm.CreateDecryptor(symm.Key, symm.IV),
                CryptoStreamMode.Read);

            // Create buffer to hold the decrypted data.
            byte[] result = new byte[length];

            // Read the decrypted data out of the crypto stream
            // and place it into the temporary buffer.
            cs.Read(result, 0, result.Length);
            return result;
        }
        catch (CryptographicException ex)
        {
            Console.WriteLine("A cryptographic error occured: {0}", ex.Message);
        }
        return null;
    }

    public string DecryptString(string data)
    {
        return Encoding.UTF8.GetString(Decrypt(Convert.FromBase64String(data))).TrimEnd('\0');
    }

    #endregion

}
public class DataEncryptor
{
    TripleDESCryptoServiceProvider symm;

    #region Factory
    public DataEncryptor()
    {
        this.symm = new TripleDESCryptoServiceProvider();
        this.symm.Padding = PaddingMode.PKCS7;
    }
    public DataEncryptor(TripleDESCryptoServiceProvider keys)
    {
        this.symm = keys;
    }

    public DataEncryptor(byte[] key, byte[] iv)
    {
        this.symm = new TripleDESCryptoServiceProvider();
        this.symm.Padding = PaddingMode.PKCS7;
        this.symm.Key = key;
        this.symm.IV = iv;
    }

    #endregion

    #region Properties
    public TripleDESCryptoServiceProvider Algorithm
    {
        get { return symm; }
        set { symm = value; }
    }
    public byte[] Key
    {
        get { return symm.Key; }
        set { symm.Key = value; }
    }
    public byte[] IV
    {
        get { return symm.IV; }
        set { symm.IV = value; }
    }

    #endregion

    #region Crypto

    public byte[] Encrypt(byte[] data) { return Encrypt(data, data.Length); }
    public byte[] Encrypt(byte[] data, int length)
    {
        try
        {
            // Create a MemoryStream.
            var ms = new MemoryStream();

            // Create a CryptoStream using the MemoryStream 
            // and the passed key and initialization vector (IV).
            var cs = new CryptoStream(ms,
                symm.CreateEncryptor(symm.Key, symm.IV),
                CryptoStreamMode.Write);

            // Write the byte array to the crypto stream and flush it.
            cs.Write(data, 0, length);
            cs.FlushFinalBlock();

            // Get an array of bytes from the 
            // MemoryStream that holds the 
            // encrypted data.
            byte[] ret = ms.ToArray();

            // Close the streams.
            cs.Close();
            ms.Close();

            // Return the encrypted buffer.
            return ret;
        }
        catch (CryptographicException ex)
        {
            Console.WriteLine("A cryptographic error occured: {0}", ex.Message);
        }
        return null;
    }

    public string EncryptString(string text)
    {
        return Convert.ToBase64String(Encrypt(Encoding.UTF8.GetBytes(text)));
    }

    public byte[] Decrypt(byte[] data) { return Decrypt(data, data.Length); }
    public byte[] Decrypt(byte[] data, int length)
    {
        try
        {
            // Create a new MemoryStream using the passed 
            // array of encrypted data.
            MemoryStream ms = new MemoryStream(data);

            // Create a CryptoStream using the MemoryStream 
            // and the passed key and initialization vector (IV).
            CryptoStream cs = new CryptoStream(ms,
                symm.CreateDecryptor(symm.Key, symm.IV),
                CryptoStreamMode.Read);

            // Create buffer to hold the decrypted data.
            byte[] result = new byte[length];

            // Read the decrypted data out of the crypto stream
            // and place it into the temporary buffer.
            cs.Read(result, 0, result.Length);
            return result;
        }
        catch (CryptographicException ex)
        {
            Console.WriteLine("A cryptographic error occured: {0}", ex.Message);
        }
        return null;
    }

    public string DecryptString(string data)
    {
        return Encoding.UTF8.GetString(Decrypt(Convert.FromBase64String(data))).TrimEnd('\0');
    }

    #endregion

}
string message="A very secret message here.";
DataEncryptor keys=new DataEncryptor();
string encr=keys.EncryptString(message);

// later
string actual=keys.DecryptString(encr);