c# decrypt sha1

Ali Yılmaz 81 Reputation points
2021-09-15T10:32:38.167+00:00

Hi,

I am struggling to decrypt users in my nopcommerce project. But when I try to solve it, I get an error. What is the reason for this error? How can i solve it.

Password : 41F954431E47BAF510C98037E7D402979D1BF318

public virtual string DecryptText(string cipherText, string encryptionPrivateKey = "")
       {
           if (String.IsNullOrEmpty(cipherText))
               return cipherText;

           if (String.IsNullOrEmpty(encryptionPrivateKey))
               encryptionPrivateKey = "8346958881167965";

           var tDESalg = new TripleDESCryptoServiceProvider();
           tDESalg.Key = Encoding.ASCII.GetBytes(encryptionPrivateKey.Substring(0, 16));
           tDESalg.IV = Encoding.ASCII.GetBytes(encryptionPrivateKey.Substring(8, 8));

           byte[] buffer = Convert.FromBase64String(cipherText);
           return DecryptTextFromMemory(buffer, tDESalg.Key, tDESalg.IV);
       }


       private string DecryptTextFromMemory(byte[] data, byte[] key, byte[] iv)
       {
           using (var ms = new MemoryStream(data))
           {
               using (var cs = new CryptoStream(ms, new TripleDESCryptoServiceProvider().CreateDecryptor(key, iv), CryptoStreamMode.Read))
               {
                   using (var sr = new StreamReader(cs, Encoding.Unicode))
                   {
                       return sr.ReadLine();
                   }
               }
           }
       }
C#
C#
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,279 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. P a u l 10,406 Reputation points
    2021-09-15T10:48:35.997+00:00

    Do you have access to the encryption methods used to generate the password?

    0 comments No comments

  2. Ali Yılmaz 81 Reputation points
    2021-09-15T11:15:16.79+00:00

    Yes i have access to everything. This code is nopcommerce own code.

    But I get error "The length of the data to be decrypted is invalid"

    I have stated above, I need to decrypt the user passwords in the database.