Back to Devexpress

ISecureDataConverter Interface

corelibraries-devexpress-dot-dataaccess-4c17dfc5.md

latest3.6 KB
Original Source

ISecureDataConverter Interface

Encrypts and decrypts any critical string data.

Namespace : DevExpress.DataAccess

Assembly : DevExpress.Data.v25.2.dll

NuGet Package : DevExpress.Data

Declaration

csharp
public interface ISecureDataConverter
vb
Public Interface ISecureDataConverter

Remarks

The ISecureDataConverter service is designed to keep any string data that’s serialized and passed between the client and server in DevExpress Reporting and Dashboard applications safe and secure.

Note

To ensure security when a Reporting or Dashboard application retrieves data from a data source that does not match any DevExpress data source type or its descendants, implement IDataSourceProtectionService.

Example

The following code example implements the ISecureDataConverter service to store connections in an XML file.

csharp
using evExpress.DataAccess;
using System;
using System.Linq;
using System.Xml.Linq;
// ...

public class CustomSecureDataConverter : ISecureDataConverter {
    const string URI = @"E:\Temp\Connections.xml";
    const string XML_CONNECTION = "Connection";
    const string XML_ID = "Id";
    static XDocument document;
    static object lockObj = new object();

    static CustomSecureDataConverter() {
        document = XDocument.Load(URI);
    }

    public string Protect(string entity) {
        var id = Guid.NewGuid().ToString();
        lock (lockObj)
            document.Root.Add(new XElement(XML_CONNECTION, new XAttribute(XML_ID, id), entity));
        return id;
    }

    public string Unprotect(string protectedEntity) {
        return document.Root.Elements(XML_CONNECTION)
            .First(x => x.Attribute(XML_ID).Value == protectedEntity)
            .Value;
    }
}
vb
Imports DevExpress.DataAccess
Imports System
Imports System.Linq
Imports System.Xml.Linq
' ...

Public Class CustomSecureDataConverter
    Implements ISecureDataConverter
    Const URI As String = "E:\Temp\Connections.xml"
    Const XML_CONNECTION As String = "Connection"
    Const XML_ID As String = "Id"
    Shared document As XDocument
    Shared lockObj As New Object()

    Shared Sub New()
        document = XDocument.Load(URI)
    End Sub

    Public Function Protect(entity As String) As String
        Dim id = Guid.NewGuid().ToString()
        SyncLock lockObj
            document.Root.Add(New XElement(XML_CONNECTION, New XAttribute(XML_ID, id), entity))
        End SyncLock
        Return id
    End Function

    Public Function Unprotect(protectedEntity As String) As String
        Return document.Root.Elements(XML_CONNECTION).First(Function(x) x.Attribute(XML_ID).Value = protectedEntity).Value
    End Function
End Class

Register a custom Data Converter implementation at application startup. ASP.NET Web Forms or MVC applications allow you to use the DefaultReportDesignerContainer.RegisterSecureDataConverter<T> method.

See Also

ISecureDataConverter Members

DevExpress.DataAccess Namespace