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

  • SEARCH
  • Home
  • 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 6697435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:27:35+00:00 2026-05-26T06:27:35+00:00

I’m hashing a password using SHA512. I’m using Entity Framework Code-First for my ORM.

  • 0

I’m hashing a password using SHA512. I’m using Entity Framework Code-First for my ORM.

Hashing Algorithm

public static string CreateSHA512Hash(string pwd, string salt)
{
    string saltAndPwd = String.Concat(pwd, salt);

    var ae = new ASCIIEncoding();
    byte[] hashValue, messageBytes = ae.GetBytes(saltAndPwd);
    var sHhash = new SHA512Managed();

    hashValue = sHhash.ComputeHash(messageBytes);

    sHhash.Dispose();

    return ae.GetString(hashValue);
}

Code for generating salt:

//Generate a cryptographic random number.
var rng = new RNGCryptoServiceProvider();
var buff = new byte[size];
rng.GetBytes(buff);

rng.Dispose();

// Return a Base64 string representation of the random number.
return Convert.ToBase64String(buff);

Problem:

For some reason, it seems the hash function would randomly generate some characters, which the ones after those are not saved to the database. In this case (I’m not sure if there are other characters that does this), but it is \0.

For eg. Password: testuser. Salt: uvq5i4CfMcOMjKPkwhhqxw==

Hash generated: ????j???7?o\0?dE??????:???s?x??u?',Vj?mNB??c???4H???vF\bd?T? (copied during dubug mode in visual studio).

But EF actually saves ????j???7?o to the database. If I try to use the text visualizer in debug mode, it cuts it off also. If you noticed, it gets cut off right at the \0. All I could find about it is that its a null character.

Question

How can I save this null character in the database using Entity Framework Code-First? If this can’t be saved, how can I prevent the SHA512 from generating these characters for me?

  • 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-26T06:27:36+00:00Added an answer on May 26, 2026 at 6:27 am

    What you should probably do:

    • Return the array of bytes for the SHA512 hash not a string.
    • Use a BINARY(64) database column to hold your hash value.

    Why your method doesn’t work:

    • These ASCII strings are NULL terminated
    • NULL is as you said \0
    • SHA512 creates a byte array and any byte can be NULL

    To answer your specific question:

    • wRAR above was saying.

      return Convert.ToBase64String(hashValue);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.