Link to home
Create AccountLog in
Avatar of Todd_Anderson
Todd_Anderson

asked on

How can I tell if a string is encrypted?

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?

Thanks,

Todd
ASKER CERTIFIED SOLUTION
Avatar of dstanley9
dstanley9

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Todd_Anderson
Todd_Anderson

ASKER

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?

Todd
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.

http://en.wikipedia.org/wiki/Base_64

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.  
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.

Todd