Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8070955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:32:54+00:00 2026-06-05T13:32:54+00:00

I have a class with a bunch of fields that need to be encrypted

  • 0

I have a class with a bunch of fields that need to be encrypted before being saved, something like this;

class MyClass
{
   public string CustomerName{ get; set; }
   public string Address1{ get; set; }
   public string Address2{ get; set; }
   public string Town{ get; set; }
   public string Postcode{ get; set; }

   // updated
   public DateTime RegistrationDate { get; set; } // don't encrypt
}

What’s the most performant approach to encrypt the fields in this object?
What about if we had to encrypt 100 or 1000 of these objects? (can we leverage TPL?)

UPDATE:
Some of the fields might not need encryption, so I don’t want to encrypt the entire class.
.NET4 is acceptable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:32:55+00:00Added an answer on June 5, 2026 at 1:32 pm

    Assuming that you finally want encrypted fields no matter you application layers, you have to time it on your own in order to get results for your system and configuration. In general your can use parallel tasks for compression as in the following sample code:

        RijndaelManaged csp = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.ISO10126 };
        // TODO: define Key and IV
        Stopwatch encryptionTime = Stopwatch.StartNew();
        Parallel.For(0, 1000, i =>
            {
                string fieldValue = "abcdef...";
                byte[] fieldBytes = UTF8Encoding.UTF8.GetBytes(fieldValue);
                byte[] fieldEncrypred;
                using (var ms = new MemoryStream())
                using (var cs = new CryptoStream(ms, csp.CreateEncryptor(), CryptoStreamMode.Write))
                {
                    cs.Write(fieldBytes, 0, fieldBytes.Length);
                    cs.FlushFinalBlock();
                    fieldEncrypred = ms.ToArray();
                }
            });
        encryptionTime.Stop();
        Console.WriteLine(encryptionTime.Elapsed.TotalMilliseconds);
    

    You can modify the above to cover your needs and perform your own tests.

    For the above sample you will need:

    using System;
    using System.Diagnostics;
    using System.IO;
    using System.Security.Cryptography;
    using System.Text;
    using System.Threading.Tasks;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a bunch of classes that look something like... class Foo{
I have a crystal report with a bunch of parameterized fields that are being
Let's say that I have a bunch of class instances that serve different purposes,
I have a bunch of business class with autoproperties : public class A {
Let's say I have one class Foo that has a bunch of logic in
Say I have: class Vector3 { float x, y, z; ... bunch of cuntions
I have a class which is essentially just holds a bunch of constant definitions
I have a bunch of class who implement a common interface : Command. And
I have a bunch of entity class (generated by Linq to SQL) with a
I have a bunch of links with the class name row. What I'm trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.