0
 
    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"); 

Как я могу зашифровать столбец Идентификатор продукта в сети kendo ui для пользователя не может увидеть мой настоящий идентификатор? Я использую ASP.NET MVC 5.asp.net mvc kendo ui grid encrypt данные столбца

Спасибо!

ответ

0

Вместо прямого шифрования вы можете использовать шаблон клиента клина кендо для столбца, в котором вы передаете значение Id функции javascript, зашифровывая ее с помощью вашего алгоритма, а затем возвращая его. что-то вроде.

columns.Bound(client => client.Id).ClientTemplate("#=Encrypt(Id)#"); 

И

<script> 
function Encrypt(id) 
{ 
// Logic to Encrypt ID 
return encryptedID.toString(); 
} 
</script> 

Если это просто, чтобы показать пользователям, тогда этого решения работает

и второе решение, чтобы просто скрыть столбец (я имею в виду не существует никакого смысла показывать идентификаторы для пользователя)

Если вы найдете эту информацию полезной, пожалуйста, отметьте как ответ

+0

спасибо ответ – gojila

0

Данные Enrcypt перед загрузкой данных в ваш код после этого связывают ваши данные.

Для этого используйте класс для encrpyt ниже

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); 
+1

спасибо за ответ – gojila

+0

вы можете надежда помогает –

Смежные вопросы