An Encrypted String Data Type for Visual Studio LightSwitch: Listing 3

Calling the EncryptedString methods.

// Initialize the encryption logic once per control

// C# class
// BlankModule.EncryptionMethods ec = new BlankModule.EncryptionMethods();

// Visual Basic class
EncryptString ec = new EncryptString();

public EncryptedStringControl()
{
  InitializeComponent();
}

private void MyBizControl_GotFocus(object sender, RoutedEventArgs e)
{
  TextBox control = (TextBox)sender;
  string result = control.Text;

  if (string.IsNullOrEmpty(control.Text) == false &&
    control.Text.EndsWith("="))
  {
    result = ec.DecryptString(control.Text);
  }
  control.Text = result;
}


private void MyBizControl_LostFocus(object sender, RoutedEventArgs e)
{
  TextBox control = (TextBox)sender;
  string result = control.Text;

  if (string.IsNullOrEmpty(control.Text) == false &&
    control.Text.EndsWith("=") == false)
  {
    result = ec.EncryptString(control.Text);
  }
  control.Text = result;
}

About the Author

Joe Kunk is a Microsoft MVP in Visual Basic, three-time president of the Greater Lansing User Group for .NET, and developer for Dart Container Corporation of Mason, Michigan. He's been developing software for over 30 years and has worked in the education, government, financial and manufacturing industries. Kunk's co-authored the book "Professional DevExpress ASP.NET Controls" (Wrox Programmer to Programmer, 2009). He can be reached via email at [email protected].

comments powered by Disqus

Featured

  • Microsoft Ships Stable Versions of OpenAI Libraries for .NET and Azure

    Further leveraging the relationship that vaulted Microsoft and OpenAI into leadership positions in the AI era, Microsoft this week announced stable versions of two new OpenAI libraries.

  • Microsoft Further Embraces OpenAPI Spec (formerly Swagger)

    Microsoft has long embraced the OpenAPI Specification (formerly known as Swagger) for describing APIs, and it's now taking that support to the next level with a new online resource.

  • Get Good at DevOps: Feature Flag Deployments with ASP.NET WebAPI

    They provide developers with the ability to toggle features on and off without having to redeploy code, making it easier to manage risk, test features in production, and facilitate smoother releases.

  • Implementing k-NN Classification Using C#

    Dr. James McCaffrey of Microsoft Research presents a full demo of k-nearest neighbors classification on mixed numeric and categorical data. Compared to other classification techniques, k-NN is easy to implement, supports numeric and categorical predictor variables, and is highly interpretable.

Subscribe on YouTube