Click here to Skip to main content
15,892,697 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionSetting grey color Pin
Member 465568523-Nov-08 22:04
Member 465568523-Nov-08 22:04 
AnswerRe: Setting grey color Pin
Alan Balkany24-Nov-08 3:59
Alan Balkany24-Nov-08 3:59 
QuestionHow do I add tabs like 3ds max [modified] Pin
akira3223-Nov-08 21:31
akira3223-Nov-08 21:31 
AnswerRe: How do I add tabs like 3ds max Pin
Cedric Moonen23-Nov-08 22:07
Cedric Moonen23-Nov-08 22:07 
AnswerRe: How do I add tabs like 3ds max Pin
Ahmed Charfeddine23-Nov-08 22:51
Ahmed Charfeddine23-Nov-08 22:51 
GeneralRe: How do I add tabs like 3ds max Pin
akira3211-Jan-09 15:29
akira3211-Jan-09 15:29 
GeneralRe: How do I add tabs like 3ds max Pin
Ahmed Charfeddine11-Jan-09 21:59
Ahmed Charfeddine11-Jan-09 21:59 
Questiondecrypting question Pin
monsieur_jj23-Nov-08 21:17
monsieur_jj23-Nov-08 21:17 
Hi all,

I have this c# decrypting code:

 public static string Decrypt(string cipherString, bool useHashing)
        {
            byte[] keyArray;
            byte[] toEncryptArray = Convert.FromBase64String(cipherString);

            System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
            //Get your key from config file to open the lock!
            string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
            
            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.CreateDecryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
                        
            tdes.Clear();
            return UTF8Encoding.UTF8.GetString(resultArray);
        }
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);
        }


No Randor advised me to do some thing inorder to translate it to c++ according to his advise by using Microsoft Cryptographic Service Providers I came up with this thanks to sources and samples, my question is why does cryptDecrypt give me zero as a result. The "Zed5OmjUWs8=" string is the encrypted value of "test" I am getting a result far from that any advice?

Thanks,
Jayjay

void ThreeDESdecrypt(unsigned char *cyphertext,unsigned long ctlen,unsigned char *passwd,unsigned long pwlen,unsigned char *plaintext,unsigned long *ptlen)
{
    HCRYPTPROV hProv = NULL;
    HCRYPTHASH hHash = NULL;
	HCRYPTKEY hKey = NULL;
	DWORD dMode;
	BYTE * value2 = {0};
	DWORD lul_len, lul_buflen, lul_skip, lul_pflags;
	bool lb_rtn;
	BLOB lblob_data;
    TCHAR* convertedStr;
	//convertedStr[0] = ('\0');
	BYTE * key1 = NULL;//[24] = {0};

	
	std::string value = "Zed5OmjUWs8=";
	lul_len = strlen(value.c_str());
	lul_buflen = (lul_len * 2);
	
	
	BOOL result = CryptStringToBinary(value.c_str(), lul_len, CRYPT_STRING_BASE64, NULL, &lul_buflen, &lul_skip, NULL);
	key1 = new BYTE [ lul_buflen ];
	memset ( key1, 0 , lul_buflen );
	result = CryptStringToBinary(value.c_str(), lul_len, CRYPT_STRING_BASE64, key1, &lul_buflen, &lul_skip, NULL);
	/*TCHAR* convertedStr = new TCHAR [lul_buflen];
	memset( convertedStr, 0 , lul_buflen );*/
	hProv = InitializeCrypt();  
	result = CryptCreateHash(hProv,CALG_MD5,0,0,&hHash);
	result = CryptHashData(hHash, passwd, pwlen, 0);
	result = CryptDeriveKey(hProv,CALG_3DES,hHash,0,&hKey);
	dMode = CRYPT_MODE_ECB;
	DWORD dwLastError = GetLastError();
	result = CryptSetKeyParam(hKey, PKCS5_PADDING, reinterpret_cast<const BYTE *>(&dMode), 0);
	memcpy(plaintext,key1,*ptlen);
	result = CryptDecrypt(hKey,hHash,1,0,plaintext,&lul_buflen);
	*ptlen=ctlen;
	CryptBinaryToString(plaintext, lul_len, CRYPT_STRING_BASE64, NULL, &lul_buflen);
	convertedStr = new TCHAR [lul_buflen];
	memset( convertedStr, 0 , lul_buflen );
	CryptBinaryToString(plaintext, lul_len, CRYPT_STRING_BASE64, convertedStr, &lul_buflen);
	result = CryptDestroyKey(hKey);
	result = CryptDestroyHash(hHash);
	result = CryptReleaseContext(hProv,0);
}

AnswerRe: decrypting question Pin
Randor 24-Nov-08 8:27
professional Randor 24-Nov-08 8:27 
GeneralRe: decrypting question Pin
monsieur_jj24-Nov-08 18:23
monsieur_jj24-Nov-08 18:23 
QuestionDifference between OnPaint and OnDraw Pin
kDevloper23-Nov-08 21:03
kDevloper23-Nov-08 21:03 
AnswerRe: Difference between OnPaint and OnDraw Pin
Ahmed Charfeddine23-Nov-08 22:58
Ahmed Charfeddine23-Nov-08 22:58 
Questionclick event for custom tree control Pin
AnithaSubramani23-Nov-08 20:59
AnithaSubramani23-Nov-08 20:59 
AnswerRe: click event for custom tree control Pin
Cedric Moonen23-Nov-08 21:04
Cedric Moonen23-Nov-08 21:04 
GeneralRe: click event for custom tree control Pin
AnithaSubramani24-Nov-08 2:35
AnithaSubramani24-Nov-08 2:35 
Questionproblem with OnItemChange function Pin
T.SREENIVASA CHARY23-Nov-08 20:44
T.SREENIVASA CHARY23-Nov-08 20:44 
AnswerRe: problem with OnItemChange function Pin
Code-o-mat23-Nov-08 23:06
Code-o-mat23-Nov-08 23:06 
GeneralRe: problem with OnItemChange function Pin
T.SREENIVASA CHARY24-Nov-08 18:21
T.SREENIVASA CHARY24-Nov-08 18:21 
GeneralRe: problem with OnItemChange function Pin
Code-o-mat24-Nov-08 21:44
Code-o-mat24-Nov-08 21:44 
GeneralRe: problem with OnItemChange function Pin
T.SREENIVASA CHARY25-Nov-08 0:27
T.SREENIVASA CHARY25-Nov-08 0:27 
Questionchat control Pin
alphaxz23-Nov-08 20:34
alphaxz23-Nov-08 20:34 
AnswerRe: chat control Pin
Hamid_RT23-Nov-08 20:44
Hamid_RT23-Nov-08 20:44 
GeneralRe: chat control Pin
alphaxz23-Nov-08 21:11
alphaxz23-Nov-08 21:11 
GeneralRe: chat control Pin
Hamid_RT24-Nov-08 2:37
Hamid_RT24-Nov-08 2:37 
QuestionGet physical drive's information like model, serial number, type, etc. Pin
Shashi.Shinde23-Nov-08 20:18
Shashi.Shinde23-Nov-08 20:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.