How can I tell if a string is encrypted?

Posted on 2007-10-08
Last Modified: 2013-11-07
I have a string that may or may not be encrypted.  The code used to encrypt the string, if it is encrypted, is below.

    Private DES As New TripleDESCryptoServiceProvider
    Private MD5 As New MD5CryptoServiceProvider
    Private Key As String = "ThisWouldBeTheKey"

    Public Function Encrypt(ByVal InputString As String)
        DES.Key = MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(Key))
        DES.Mode = CipherMode.ECB

        Dim Buffer As Byte() = ASCIIEncoding.ASCII.GetBytes(InputString)

        Return Convert.ToBase64String(DES.CreateEncryptor().TransformFinalBlock(Buffer, 0, Buffer.Length))
    End Function

Is there a way to determine if the string is encrypted or not?


Question by:Todd_Anderson
    LVL 25

    Accepted Solution

    No definite way that I know of.  There may be clues - length of the string, presence of certain characters, etc.

    Why is the string only encrypted part of the time?

    Author Comment

    Its a long story on why the string may or may not be encrypted.  Not really the issue here though.

    I was just looking at the encrypted strings and all of the longer ones have double equal signs at the end (==) and the shorter ones have single equals signs at the end (=).  Every hear of this being a sign of encryption?

    LVL 25

    Expert Comment

    Base64 pads strings with equals signs if the encoded string's length is not a multiple of 3.  Every three bytes are encoded into 4 ASCII characters.  If the source string does not contain an even multiple of three characters, one or two equals signs are added to indicate how long the last triplet is.

    However, Base64 is an encoding method, not an encryption method.  It is a way to encode binary data into a smaller subset of characters to be transmitted without having to support all 256 possible values of a byte.  There is no guarantee that the encoded string will contain an equals sign.  In fact if the lengths of the strings are random, then statistically one out of every three strings will NOT have an equals sign.  

    Even if you know the string is base-64, you still don't know if the source string is the original source or an encrypted version.  

    Author Comment

    Ok, I guess I will have to look at one of my backup plans.  I was hoping that I could detect the encryption since it is the most straight forward.

    Thanks for the help.


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Suggested Solutions

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now