How to decrypt password from database?

Takeshi 41 Reputation points

Hi all,

  • I have created "Decrypt" function
  • If I put in function a string pass ... like ... Decrypt("asd4as5da6a<6asd/?") ... it return correct password
  • BUT if I read from database and put this into this function ... like ... Decrypt(dr[1].ToString()) ... it return nothing ... blank text ... I am sure from database I read a string ... there is something ... because I tried to read this encrypted text ... It appear ... but when I use this decrypt function .. problem
  • so I dont understand
  • Can someone help me?

Thank you!

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,181 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Jiale Xue - MSFT 30,126 Reputation points Microsoft Vendor

    Hi @Takeshi , Welcome to Microsoft Q&A,

    Updated: It store diffent encrypter string to second database.

    Solve the problem of character changes.

    When reading strings from the database, make sure to use the correct character encoding. If different character encodings are used between the database and application, string parsing errors may result. You can use the Encoding class to explicitly specify the character encoding.

    Before passing the string to the decryption function, sanitize it to ensure that no extra whitespace characters or special characters interfere with the decryption process. You can use the Trim() method to remove whitespace characters from both ends of a string.

    Best Regards,


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

  2. Karen Payne MVP 35,026 Reputation points

    If this is SQL-Server check out Passwords in SQL-Server C#

    0 comments No comments