Click here to Skip to main content
15,903,854 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
Hi ,

I am using follwoing process to Encrypt the certain text .How can i decrypt the result.

public static string GetSHA256(string text)
  {
      UnicodeEncoding ue = new UnicodeEncoding();
      byte[] hashValue;
      //byte[] message = ue.GetBytes("NYRR" + text + "RRYN");
      byte[] message = ue.GetBytes(text.Length * 2 + text + text.Length * 2);

      SHA256Managed hashString = new SHA256Managed();
      string hex = "";

      hashValue = hashString.ComputeHash(message);
      foreach (byte x in hashValue)
      {
          hex += String.Format("{0:x2}", x);
      }
      return hex;
  }


What I have tried:

C#
public static string GetSHA256(string text)
  {
      UnicodeEncoding ue = new UnicodeEncoding();
      byte[] hashValue;
      //byte[] message = ue.GetBytes("NYRR" + text + "RRYN");
      byte[] message = ue.GetBytes(text.Length * 2 + text + text.Length * 2);

      SHA256Managed hashString = new SHA256Managed();
      string hex = "";

      hashValue = hashString.ComputeHash(message);
      foreach (byte x in hashValue)
      {
          hex += String.Format("{0:x2}", x);
      }
      return hex;
  }
Posted
Updated 7-Oct-16 4:56am

Hash functions like SHA etc. are by definition one-way meaning that the process of hashing will loose information in the result, and cannot be used for encryption.
 
Share this answer
 
Quote:
How can decrypte SHA256
You can't because SHA256 is not encryption.
It is like with numerology. In numerology you give give a value to a name by summing the values given to each letters, you can't reverse the process.
 
Share this answer
 
SHA256 is a hashing method, not an encryption method. You can't decrypt a hash value because it's a mathematically determined value based on the value of the string being hashed.
 
Share this answer
 
SHA256 like everybody has said is a one way hashing technique. Once a text has been hashed, it cannot be "decryted" again. I would suggest you create a salt with your and append it to the hashed text. That way, you get to use it for users authentication.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900