Articles in this section
Category / Section

How to Encrypt Connection Strings in Bold Reports Embedded Applications

Published:
Updated:

In Bold Reports embedded applications, connection strings often contain sensitive information such as database credentials. Encrypting these strings adds an essential layer of security when they are processed by the Report Designer.

This guide walks you through the simple steps to enable encryption for connection strings.

Steps to Encrypt Connection Strings

Step 1: Update the Designer Page (DesignReport.cshtml)

Modify the JavaScript initialization of the Bold Reports Designer to include encryption support:

$('#' + controlId).boldReportDesigner({
    serviceUrl: "/api/ReportDesigner",
    create: "controlInitialized",
    toolbarSettings: {
        items: ej.ReportDesigner.ToolbarItems.All 
            & ~ej.ReportDesigner.ToolbarItems.Save
            & ~ej.ReportDesigner.ToolbarItems.Open 
            & ~ej.ReportDesigner.ToolbarItems.New
    },
    toolbarClick: "toolbarClick",
    toolbarRendering: "toolbarRendering",
    reportModified: "reportModified",
    reportSaved: "reportSaved",
    encryptData: "encryptData",           // ← Enables encryption
    ajaxBeforeLoad: "ajaxBeforeSendReq"
});
Property Description
encryptData Specifies the function that handles encryption of connection strings and other data.

Step 2: Implement Encryption Logic in ReportDesignerController.cs

Add the following method to your controller to perform encryption using the key and iv variables from request headers:

public string EncryptData(string plainText)
{
    try
    {
        var key = GetHeaderValue("keyCode");
        var iv  = GetHeaderValue("ivCode");

        if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(iv))
            return plainText;   // fallback if headers missing

        return EncryptString(plainText, key, iv);
    }
    catch
    {
        return plainText;       // graceful fallback
    }
}

Helper Method (add if not already present):

private string GetHeaderValue(string headerName)
{
    return Request.Headers[headerName].FirstOrDefault();
}

Preview and Verification

Before Encryption
The connection string appears in plain text within the designer.

Before Encryption

After Encryption
The connection string is securely encrypted.
Encrypted Connection String

Conclusion

Encrypting connection strings in Bold Reports Designer is a quick and effective way to protect sensitive database credentials. By adding just two lines in your designer page and a simple encryption method in the controller, you significantly strengthen the security of your embedded reporting application.

Sample Application: Download the complete working example here.

Related Articles

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied