-3

I have an encrypted database in which the strings are values like the below: ùœ¢Qa³•ù¼?-pJ´’ˆò»Æ8-skYIÞµ§¬†Œ‚„Šç

ù¢=~Òñ€Ï?-pJ´’ˆò»Æ8-skYIÞµ§¬†Œ‚„Šç

XwÚûùÖP^opJ´’ˆò»Æ8-skYIÞµ§¬†Œ‚„Šç

ö‘±_|Çúùß^_f9´’ˆò»Æ8-skYIÞµ§¬†Œ‚„Šç

I'm trying different ways to dencrypt the information (it's a simmetric encryption and I have the key, but I don't know the algorithm, more detail here How to decrypt a string encrypted by V FoxPro)

When I tried different ways to dencrypt using C#.NET in an step I get àn error saying that "the string has a non-base64 character" in the following line:

Convert.FromBase64String(input)

Where input is a string similar to the one I share above.

How Can I receive an string like that from DB in order to work with that in C#?

Community
  • 1
  • 1
  • 1
    You should go learn what Base64 encoding is. You seem to have just copy+pasted some code without understanding it.. the strings above are clearly not base64 encoded. – Blorgbeard Mar 04 '15 at 02:53
  • I know that is not Base64... For that reason I'm posting this question. So, do you know which encoding is? – Fabian Angeloni Mar 05 '15 at 03:11
  • Then why did you `Convert.FromBase64String(input)`? Anyway, if you don't know the encryption algorithm, you've got bigger problems than the encoding.. – Blorgbeard Mar 05 '15 at 03:18
  • Without any code (for how did you get this data), the question is unanswerable. Your 'string' is not really a string, it's probably a `byte[]` – H H Mar 07 '15 at 09:08

1 Answers1

0

I normally use something like this:

public static class EncryptDecryptString
{
    public static string Encrypt(string input, string key)
    {
        byte[] inputArray = UTF8Encoding.UTF8.GetBytes(input);
        TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
        tripleDES.Key = UTF8Encoding.UTF8.GetBytes(key);
        tripleDES.Mode = CipherMode.ECB;
        tripleDES.Padding = PaddingMode.PKCS7;
        ICryptoTransform cTransform = tripleDES.CreateEncryptor();
        byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length);
        tripleDES.Clear();
        return Convert.ToBase64String(resultArray, 0, resultArray.Length);
    }

    public static string Decrypt(string input, string key)
    {
        byte[] inputArray = Convert.FromBase64String(input);
        TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
        tripleDES.Key = UTF8Encoding.UTF8.GetBytes(key);
        tripleDES.Mode = CipherMode.ECB;
        tripleDES.Padding = PaddingMode.PKCS7;
        ICryptoTransform cTransform = tripleDES.CreateDecryptor();
        byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length);
        tripleDES.Clear();
        return UTF8Encoding.UTF8.GetString(resultArray);
    }

}
zXSwordXz
  • 176
  • 4
  • 15
  • I had something like that, but that fail in decryption method in the following line: Convert.FromBase64String(input); because the encripted text is not Base64String – Fabian Angeloni Mar 05 '15 at 03:10