How to generate Hash in asp.net C#?
Example: SHA512(requestId + "#" + status + "#"+ responseCode + "#" + aadhaarId + "#" + availableBalance + "#" salt)
How to generate Hash in asp.net C#?
Example: SHA512(requestId + "#" + status + "#"+ responseCode + "#" + aadhaarId + "#" + availableBalance + "#" salt)
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajkiran SwainRank #165 · 14.4K reputationPosted Apr 20, 2023, 3:22 AM EDT
using System.Security.Cryptography; using System.Text; // Initialize variables string requestId = "123456789"; string status = "success"; string responseCode = "200"; string aadhaarId = "123456789012"; string availableBalance = "1000"; string salt = "mysalt123"; // Concatenate values into a string string message = requestId + "#" + status + "#" + responseCode + "#" + aadhaarId + "#" + availableBalance + "#" + salt; // Convert message string to byte array byte[] messageBytes = Encoding.UTF8.GetBytes(message); // Create SHA-512 hash object SHA512 sha512 = SHA512.Create(); // Compute hash value byte[] hashBytes = sha512.ComputeHash(messageBytes); // Convert hash to string string hashString = BitConverter.ToString(hashBytes).Replace("-", "");Vishal YelveRank #178 · 13.6K reputationPosted Apr 20, 2023, 9:22 AM EDT
Hi Jagapathibabu,
Do refer below links
https://www.techiedelight.com/generate-sha-512-hash-for-input-data-csharp/
https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha512?view=net-7.0
https://riptutorial.com/csharp/example/9345/sha512
Jagapathibabu Banoth166 reputationPosted Apr 21, 2023, 3:17 AM EDT
Without Initialize variables How can I generate The Hash Sir....
Vishal YelveRank #178 · 13.6K reputationPosted Apr 21, 2023, 5:44 AM EDT
Hi Jagapathibabu,
check this.
using System; using System.Text; using System.Security.Cryptography; public class Example { static string ComputeSHA512(string s) { StringBuilder sb = new StringBuilder(); using (SHA512 sha512 = SHA512.Create()) { byte[] hashValue = sha512.ComputeHash(Encoding.UTF8.GetBytes(s)); foreach (byte b in hashValue) { sb.Append($"{b:X2}"); } } return sb.ToString(); } public static void Main() { string hashValue = ComputeSHA512("Some string"); Console.WriteLine(hashValue); } }Tuhin PaulRank #7 · 71.9K reputationPosted Apr 21, 2023, 10:09 PM EDT
You can generate the hash without initializing the variables first.see the code:
using System.Security.Cryptography; using System.Text; // Set the values directly string requestId = "123456789"; string status = "success"; string responseCode = "200"; string aadhaarId = "123456789012"; string availableBalance = "1000"; string salt = "mysalt123"; // Concatenate values into a string string message = requestId + "#" + status + "#" + responseCode + "#" + aadhaarId + "#" + availableBalance + "#" + salt; // Convert message string to byte array byte[] messageBytes = Encoding.UTF8.GetBytes(message); // Create SHA-512 hash object SHA512 sha512 = SHA512.Create(); // Compute hash value byte[] hashBytes = sha512.ComputeHash(messageBytes); // Convert hash to string string hashString = BitConverter.ToString(hashBytes).Replace("-", "");The values for `requestId`, `status`, `responseCode`, `aadhaarId`, `availableBalance`, and `salt` are set directly in the code. You can replace these values with the appropriate variables or values from your own code.