-1

I want to decrypt the string which has been encrypted by an application in C#.Net by using the following methods:

      public static class clsEncryptions
{
    public static string GetKey()
    {
        var key = new { key = "MyKey" };
        return key.key;
    }

    public static string Encrypt(this string EncryptString)
    {
        if (EncryptString == string.Empty)
            return string.Empty;
        byte[] clearBytes =
          System.Text.Encoding.Unicode.GetBytes(EncryptString);
        PasswordDeriveBytes pdb = new PasswordDeriveBytes(GetKey(),
            new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 
        0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});

        MemoryStream ms = new MemoryStream();
        Rijndael alg = Rijndael.Create();
        alg.Key = pdb.GetBytes(32);
        alg.IV = pdb.GetBytes(16);
        CryptoStream cs = new CryptoStream(ms, alg.CreateEncryptor(),CryptoStreamMode.Write);
        cs.Write(clearBytes, 0, clearBytes.Length);
        cs.Close();
        return Convert.ToBase64String(ms.ToArray());
    }


    public static string Decrypt(this string DecryptString)
    {
        if (DecryptString == string.Empty)
            return string.Empty;
        byte[] cipherBytes = Convert.FromBase64String(DecryptString);
        PasswordDeriveBytes pdb = new PasswordDeriveBytes(GetKey(),
                        new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 
        0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
        MemoryStream ms = new MemoryStream();
        Rijndael alg = Rijndael.Create();
        alg.Key = pdb.GetBytes(32);
        alg.IV = pdb.GetBytes(16);
        CryptoStream cs = new CryptoStream(ms, alg.CreateDecryptor(), CryptoStreamMode.Write);
        cs.Write(cipherBytes, 0, cipherBytes.Length);
        cs.Close();
        return System.Text.Encoding.Unicode.GetString(ms.ToArray());
    }
}

Please help me to convert the Decryption Logic in to VC++(MFC project) so that i could be able to read the encrypted file in my VC++ application.

1

1 Answer 1

0

have you tried looking at those

  1. http://www.cryptopp.com/ this is C++ encryption library that will help you
  2. http://pocoproject.org/ this is a c++ framework that has encryption classes that you will need

my advice is to use cryptopp to get smaller application size, but poco is easier in code writing and produce a bigger exe size in static linking, that what i noticed this may not be correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.