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. Encrytion and decryption a string [modified]

Encrytion and decryption a string [modified]

Scheduled Pinned Locked Moved C#
securityhelpquestionworkspace
2 Posts 2 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

    Hello anyone.., How we can differentiate between an encrypted and none encrypted txt??? i need a method for that, to using in my project..., Please help me.........,,, An encryption methode is below:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Security.Cryptography;
    using System.Configuration;

    namespace SharpPcap.EnCryptDecrypt
    {
    public class CryptorEngine
    {
    public static string Encrypt(string toEncrypt, bool useHashing)
    {
    byte[] keyArray;
    byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt);

            System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
            // Get the key from config file
            string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
            //System.Windows.Forms.MessageBox.Show(key);
            if (useHashing)
            {
                MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
                keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
                hashmd5.Clear();
            }
            else
                keyArray = UTF8Encoding.UTF8.GetBytes(key);
    
            TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
            tdes.Key = keyArray;
            tdes.Mode = CipherMode.ECB;
            tdes.Padding = PaddingMode.PKCS7;
    
            ICryptoTransform cTransform = tdes.CreateEncryptor();
            byte\[\] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
            tdes.Clear();
            return Convert.ToBase64String(resultArray, 0, resultArray.Length);
        }
    }
    

    }

    Regards...

    modified on Wednesday, January 27, 2010 6:56 AM

    K 1 Reply Last reply
    0
    • 3 3bood ghzawi

      Hello anyone.., How we can differentiate between an encrypted and none encrypted txt??? i need a method for that, to using in my project..., Please help me.........,,, An encryption methode is below:

      using System;
      using System.Collections.Generic;
      using System.Text;
      using System.Security.Cryptography;
      using System.Configuration;

      namespace SharpPcap.EnCryptDecrypt
      {
      public class CryptorEngine
      {
      public static string Encrypt(string toEncrypt, bool useHashing)
      {
      byte[] keyArray;
      byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt);

              System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
              // Get the key from config file
              string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
              //System.Windows.Forms.MessageBox.Show(key);
              if (useHashing)
              {
                  MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
                  keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
                  hashmd5.Clear();
              }
              else
                  keyArray = UTF8Encoding.UTF8.GetBytes(key);
      
              TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
              tdes.Key = keyArray;
              tdes.Mode = CipherMode.ECB;
              tdes.Padding = PaddingMode.PKCS7;
      
              ICryptoTransform cTransform = tdes.CreateEncryptor();
              byte\[\] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
              tdes.Clear();
              return Convert.ToBase64String(resultArray, 0, resultArray.Length);
          }
      }
      

      }

      Regards...

      modified on Wednesday, January 27, 2010 6:56 AM

      K Offline
      K Offline
      Keith Barrow
      wrote on last edited by
      #2

      3bood.ghzawi wrote:

      How we can differentiate between an encrypted and none encrypted txt???

      You can't, not without decrypting. It is possible to perform a preliminary check to see whether the decryption "string" is HEX (which encrypted strings are), but not all HEX strings are encrypted information. The only reliable way is to attempt to decrypt, even then it only checks for the decryption key. Also this is worrying:

      3bood.ghzawi wrote:

      // Get the key from config file string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));

      The app config is by-and-large publicly available, and the key *MUST* be kept secret for the cryptography to be worth anything.

      CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks

      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