0

I need to create a sha256 hash of a password entered in a TextBox. I tried to use ComputeHash(string) but it only works with streams.

erosfabbri
  • 37
  • 1
  • 8
  • 1
    This could give you the tip needed.https://stackoverflow.com/questions/1879395/how-do-i-generate-a-stream-from-a-string – Steve Feb 20 '20 at 19:06
  • @Steve link is good for starters, but if looking at the accepted answer there, remember the encoding isn't in place and which may be of importance. – Trevor Feb 20 '20 at 20:38
  • 1
    @Çöđěxěŕ yes, there is a very important comment under the accepted answer and the second upvoted answer addresses it even better. – Steve Feb 20 '20 at 20:46
  • 1
    Maybe: `Dim hash = New System.Security.Cryptography.SHA256Managed().ComputeHash(System.Text.Encoding.UTF8.GetBytes("The-password"))`. Also check [Rfc2898DeriveBytes](https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.rfc2898derivebytes?view=netframework-4.8) –  Feb 20 '20 at 20:59
  • 2
    Yeah, this is a method with a few overloads, so the "only works with streams" part is a bad preconception. And more importantly, the idea that you use a cryptographic hash on a password is probably another one. – Maarten Bodewes Feb 20 '20 at 22:38

1 Answers1

1
Dim hash = New System.Security.Cryptography.SHA256Managed().ComputeHash(System.Text.Encoding.UTF8.GetBytes("The-password"))
erosfabbri
  • 37
  • 1
  • 8