1

i am working on an encryption and decryption application using visual studio c#, my encryption and decryption of text works but i am trying to add a password for the text when encrypted and for the application to ask for a password when decrypting the text, as in the user gets to input a custom password when encrypting and when decrypting the user gets to input the password and text decrypts.

   using System.Security.Cryptography;

public static string EncodePasswordToBase64(string password)    
{  byte[] bytes   = Encoding.Unicode.GetBytes(password);    
   byte[] inArray = HashAlgorithm.Create("SHA1").ComputeHash(bytes);    
   return Convert.ToBase64String(inArray);   

}

Aatkaa
  • 11
  • 1
  • 1
    Hi and welcome to Stack Overflow. Can you elaborate on what you're really asking? Your hashing method seems fine, though I would recommend reading up on SALTing it. – Lasse V. Karlsen Jul 26 '21 at 06:46
  • the response it does run correctly with my code cause want it request a password when encrypting and when decrypting – Aatkaa Jul 26 '21 at 06:49
  • 1
    Please do not use a hash to create an encryption key from a password, it leads to easy bruteforce attacks. Use a [key derivation algorithm](https://docs.microsoft.com/en-us/uwp/api/windows.security.cryptography.core.keyderivationalgorithmprovider?view=winrt-20348). – JonasH Jul 26 '21 at 06:52
  • I guess you will get you answer here. [blog]: https://stackoverflow.com/questions/10168240/encrypting-decrypting-a-string-in-c-sharp – Art Abrahamyan Jul 26 '21 at 06:53

0 Answers0