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 196211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:44:53+00:00 2026-05-11T16:44:53+00:00

The idea is to produce utility class , so that whenever the guys hack

  • 0

The idea is to produce utility class , so that whenever the guys hack the best currently known algorithms and new one comes to the market the only think that the Developer would have to do is to add the NewHighTechEncryptingAlgorithm_Encryptor class and change a global application setting for NewHighTechEncryptingAlgorithm_As_String

so that the call would be
string myNewEncryptedString = Encryptor.Encrypt(StringToEncrypt , strAlgorithmName)

Edit: I removed the old code and pasted the answer, provided by rwwilden with the calling code

I quess the proper wording would be “Enhashing” as oppose of “Encryption” since no salt is envolved here … this seems to be the best solution according to the proposed “specs”

 using System;
 using System.Text;
 using System.Security.Cryptography;

 namespace GenApp.Utils.Security
 {

 /// <summary>
 /// Summary description for Encrypter
 /// </summary>
 public class Encrypter 
 {
 /// <summary>
 /// Encrypts according to the passed plain name for hasing algorithm
 /// see CryptoConfig class from MSDN for more details
 /// </summary>
 /// <param name="strPlainTxt">the plain text to encrypt</param>
 /// <param name="strAlgorithmName">The plain name of the hashing algorithm </param>
 /// <returns> the encrypted string </returns>
 public static string Encrypt ( string strPlainTxt, string strAlgorithmName )
 {
  string strHashedTxt = String.Empty;
  byte[] bytPlain = System.Text.Encoding.UTF8.GetBytes ( strPlainTxt );


  using (HashAlgorithm objAlgorithm = HashAlgorithm.Create ( strAlgorithmName ))
  {
   byte[] bytHash = objAlgorithm.ComputeHash ( bytPlain );
   strHashedTxt = Convert.ToBase64String ( bytHash );
   return strHashedTxt; 
  } 

 } //eof method 


 ///// OLD CODE - REQUIRES RECODING 
 ///// <summary>
 ///// Encrypts according to the passed plain name for hasing algorithm
 ///// see CryptoConfig class from MSDN for more details
 ///// </summary>
 ///// <param name="strPlainTxt">the plain text to encrypt</param>
 ///// <param name="strAlgorithmName">The plain name of the hashing algorithm </param>
 ///// <returns> the encrypted string </returns>
 //public static string Encrypt ( string strPlainTxt, string strAlgorithmName )
 //{
 //  string strHashedTxt = String.Empty;
 //  byte[] bytPlains = System.Text.Encoding.UTF8.GetBytes ( strPlainTxt );
 //  byte[] bytHash;
 //  //CryptoConfig objCryptoConfig = new CryptoConfig ();


 //  switch (strAlgorithmName)
 //  {
 //    case "SHA1":
 //      SHA1CryptoServiceProvider objProvForSHA1alg =
 //        (SHA1CryptoServiceProvider)CryptoConfig.CreateFromName ( strAlgorithmName );


 //      bytHash = objProvForSHA1alg.ComputeHash ( bytPlains );
 //      objProvForSHA1alg.Clear ();
 //      strHashedTxt = Convert.ToBase64String ( bytHash );

 //      break;
 //    case "MD5" :

 //      MD5CryptoServiceProvider objProvForMD5alg =
 //        (MD5CryptoServiceProvider)CryptoConfig.CreateFromName ( strAlgorithmName );

 //      bytHash = objProvForMD5alg.ComputeHash ( bytPlains );
 //      strHashedTxt = Convert.ToBase64String ( bytHash );
 //      objProvForMD5alg.Clear ();


 //      break; 

 //  } //eof switch

 //  if (String.IsNullOrEmpty ( strHashedTxt ))
 //    throw new Exception ( "Encryption provider called by invalide simple name " );


 //  return strHashedTxt;
 //} //eof method 


 } //eof class 


 class Program
 {
 static void Main ( string[] args )
 {
  string strPlainTxt = "UnEncryptedText";
  string strAlgorithmName = "SHA1"; //the type of al
  string strHashedTxt = String.Empty;

  //START WITH ONE ALGORITHM
  Console.WriteLine ( "Using the " + strAlgorithmName + " START " );
  Console.WriteLine ( "The plain text is " + strPlainTxt );
  Console.WriteLine ( "The encrypting algorithm is " + strAlgorithmName );
  strHashedTxt = Encrypter.Encrypt ( strPlainTxt, strAlgorithmName );
  Console.WriteLine ( "The hashed text is " + strHashedTxt );
  Console.WriteLine ( "Using the " + strAlgorithmName + " END " );

  //NOW CHANGE THE ALGORITHM
  strAlgorithmName = "MD5";
  Console.WriteLine ( "Using the " + strAlgorithmName + " START " );
  Console.WriteLine ( "The plain text is " + strPlainTxt );
  Console.WriteLine ( "The encrypting algorithm is " + strAlgorithmName );
  strHashedTxt = Encrypter.Encrypt ( strPlainTxt, strAlgorithmName );
  Console.WriteLine ( "The hashed text is " + strHashedTxt );
  Console.WriteLine ( "Using the " + strAlgorithmName + " END " );


  strAlgorithmName = "SHA256";
  Console.WriteLine ( "Using the " + strAlgorithmName + " START " );
  Console.WriteLine ( "The plain text is " + strPlainTxt );
  Console.WriteLine ( "The encrypting algorithm is " + strAlgorithmName );
  strHashedTxt = Encrypter.Encrypt ( strPlainTxt, strAlgorithmName );
  Console.WriteLine ( "The hashed text is " + strHashedTxt );
  Console.WriteLine ( "Using the " + strAlgorithmName + " END " );


  Console.WriteLine ( "Hit enter to exit" );
  Console.ReadLine ();
 }

 }
 } //eof namespace 
  • 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-05-11T16:44:53+00:00Added an answer on May 11, 2026 at 4:44 pm

    You should take a look at the CryptoConfig class. Especially the method CreateFromName. It provides a way to obtain a cryptographic algorithm based on a name (that you supply in your configuration). Changing the name in your configuration automatically changes the algorithm used.

    If you have made a choice on whether to use symmetric or asymmetric encryption, you should use the more specific SymmetricAlgorithm.Create(string) or AsymmetricAlgorithm.Create(string) methods.

    Since you require a hashing solution, you should use HashAlgorithm.Create(string). The reason for implementing it as I do below is that you do not have to change any code when you decide to use another hashing algorithm. In your code you have to add another case statement.

    public static string Encrypt(string toEncrypt, string algorithmName)
    {
        byte[] bytePlain = System.Text.Encoding.UTF8.GetBytes ( strPlainTxt );
        using (HashAlgorithm algorithm = HashAlgorithm.Create(algorithm))
        {
            byte[] byteHash = algorithm.ComputeHash(bytePlain);
            string strHashedTxt = Convert.ToBase64String (byteHash);
            return strHashedTxt;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 173k
  • Answers 174k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No, because objects can be moved from OU to OU.… May 12, 2026 at 2:47 pm
  • Editorial Team
    Editorial Team added an answer Basically what will happen is that you will get the… May 12, 2026 at 2:47 pm
  • Editorial Team
    Editorial Team added an answer If you are trying to restrict a property to one… May 12, 2026 at 2:47 pm

Related Questions

I have a WinForms .NET app that, according to the Vista Task Manager with
I'm trying to produce a pretty simple XML schema for an XML similar to
The offline installer for .NET Framework 3.5 SP1 is 200 MB large. We're wondering
I tried to write a TransformMesh function. The function accepts a Mesh object and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.