Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Decryption algorithm

Decryption algorithm

Scheduled Pinned Locked Moved C#
algorithmsdata-structureshelpworkspace
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 3 Offline
    3 Offline
    3bood ghzawi
    wrote on last edited by
    #1

    Hi all, as runing this algorithm, that decrypt an encrypted array of bytes, allways returns null as a decrypted result... the code is below:

    public static void Decrypt(byte[] toEncryptArray, bool useHashing)
    {
    System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
    //Get your key from config file to open the lock!
    string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));

            if (useHashing)
            {
                MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
                D\_keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
                hashmd5.Clear();
            }
            else
                D\_keyArray = UTF8Encoding.UTF8.GetBytes(key);
    
            TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
            tdes.Key = D\_keyArray;
            tdes.Mode = CipherMode.ECB;
            tdes.Padding = PaddingMode.PKCS7;
    
            ICryptoTransform cTransform = tdes.CreateDecryptor();
            byte\[\] D\_resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
           
             //  the D\_resultArray always get a null value
            tdes.Clear();
       }
    

    Can any one help me ,,,,,,,,, i'll be very thanks.., regards :-D

    L 1 Reply Last reply
    0
    • 3 3bood ghzawi

      Hi all, as runing this algorithm, that decrypt an encrypted array of bytes, allways returns null as a decrypted result... the code is below:

      public static void Decrypt(byte[] toEncryptArray, bool useHashing)
      {
      System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
      //Get your key from config file to open the lock!
      string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));

              if (useHashing)
              {
                  MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
                  D\_keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
                  hashmd5.Clear();
              }
              else
                  D\_keyArray = UTF8Encoding.UTF8.GetBytes(key);
      
              TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
              tdes.Key = D\_keyArray;
              tdes.Mode = CipherMode.ECB;
              tdes.Padding = PaddingMode.PKCS7;
      
              ICryptoTransform cTransform = tdes.CreateDecryptor();
              byte\[\] D\_resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
             
               //  the D\_resultArray always get a null value
              tdes.Clear();
         }
      

      Can any one help me ,,,,,,,,, i'll be very thanks.., regards :-D

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      http://msdn.microsoft.com/en-us/library/system.security.cryptography.tripledescryptoserviceprovider.aspx[^] use the sample there...

      3 1 Reply Last reply
      0
      • L Lost User

        http://msdn.microsoft.com/en-us/library/system.security.cryptography.tripledescryptoserviceprovider.aspx[^] use the sample there...

        3 Offline
        3 Offline
        3bood ghzawi
        wrote on last edited by
        #3

        very thanks stancrm, but sorry, i really new at C# and don't understand that........ can you make it more esey ...; thanks.., :-D

        M N 2 Replies Last reply
        0
        • 3 3bood ghzawi

          very thanks stancrm, but sorry, i really new at C# and don't understand that........ can you make it more esey ...; thanks.., :-D

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          Here let me help Stan out.... Follow the link to the MSDN article Read the article to understand what you are doing Locate the c# sample in the article Highlight the sample code Copy it to the clipboard Open you test application Locate where you want to work with the sample Paste the sample into your app Wire up the events required to test the sample Create the objects required by the sample (you should understand these needs from reading the article) Put in a break point in your code Run the app. Step through the code and inspect the objects to understand in detail what you are doing. Wheres the spoon icon!!!!!

          Never underestimate the power of human stupidity RAH

          A 1 Reply Last reply
          0
          • 3 3bood ghzawi

            very thanks stancrm, but sorry, i really new at C# and don't understand that........ can you make it more esey ...; thanks.., :-D

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #5

            3bood.ghzawi wrote:

            can you make it more easy

            :rolleyes: :omg: :wtf: You have been provided with basic cut & paste code to show you how to do it. How much easier do you want it? If you can't understand this example then you shouldn't even be attempting encryption.


            I know the language. I've read a book. - _Madmatt

            modified on Tuesday, February 2, 2010 6:54 PM

            1 Reply Last reply
            0
            • M Mycroft Holmes

              Here let me help Stan out.... Follow the link to the MSDN article Read the article to understand what you are doing Locate the c# sample in the article Highlight the sample code Copy it to the clipboard Open you test application Locate where you want to work with the sample Paste the sample into your app Wire up the events required to test the sample Create the objects required by the sample (you should understand these needs from reading the article) Put in a break point in your code Run the app. Step through the code and inspect the objects to understand in detail what you are doing. Wheres the spoon icon!!!!!

              Never underestimate the power of human stupidity RAH

              A Offline
              A Offline
              AspDotNetDev
              wrote on last edited by
              #6

              That's some good spoon feeding you've got going on there. :laugh:

              [Forum Guidelines]

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups