|
Hello member..
Do you mean a TabbedToolBar in which tabs you' going to put buttons ??
Something like :
http://www.bcgsoft.com/featuretour/tour26.htm[^]
If that is the case, then check if you cabn find this in the MFC Feature Pack since BCGControlBar has been integrated into MFC.
|
|
|
|
|
Thank you,hINTModuleState! Is there any free source code for the tab view(/dialog) like 3ds max?
|
|
|
|
|
|
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();
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();
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.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;
BYTE * key1 = NULL;
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);
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);
}
|
|
|
|
|
Hello again JayJay,
I have written a sample for you. It doesn't get any better than this.
#include "stdafx.h"
#include <windows.h>
#include <Wincrypt.h>
#include <assert.h>
#pragma comment(lib, "crypt32.lib")
LPTSTR Base64Decode(LPCTSTR lpData, DWORD dwSize)
{
DWORD dwResult = 0;
if(CryptStringToBinary(lpData, dwSize, CRYPT_STRING_BASE64, NULL, &dwResult,NULL,NULL))
{
LPTSTR lpszBase64Decoded = new TCHAR[dwResult+(sizeof(TCHAR) * 2)];
memset(lpszBase64Decoded,0,dwResult);
if(CryptStringToBinary(lpData, dwSize, CRYPT_STRING_BASE64,(BYTE *)lpszBase64Decoded, &dwResult,NULL,NULL))
{
*(LPWORD)(lpszBase64Decoded + (dwResult / sizeof(TCHAR))) = 0;
return lpszBase64Decoded;
}
}
return NULL;
}
LPTSTR Base64Encode(LPCBYTE lpData, DWORD dwSize, BOOL bStripCRLF)
{
DWORD dwResult = 0;
if(CryptBinaryToString(lpData, dwSize, CRYPT_STRING_BASE64, NULL, &dwResult))
{
LPTSTR lpszBase64 = new TCHAR[dwResult];
if(CryptBinaryToString(lpData, dwSize, CRYPT_STRING_BASE64, lpszBase64, &dwResult))
{
TCHAR pByteLF = *(LPWORD)(lpszBase64 + dwResult -1);
TCHAR pByteCR = *(LPWORD)(lpszBase64 + dwResult -2);
if(pByteCR == 0x0D && pByteLF == 0x0A)
{
*(LPWORD)(lpszBase64 + dwResult -2) = 0;
}
return lpszBase64;
}
}
return NULL;
}
DWORD TripleDESencrypt(TCHAR *plaintext,DWORD ptlen,TCHAR *passwd,DWORD pwlen,TCHAR *cyphertext,DWORD *ctlen)
{
HCRYPTPROV hProv;
HCRYPTHASH hHash;
HCRYPTKEY hKey;
DWORD dwSizeNeeded =0;
DWORD sz =0;
CryptAcquireContext(&hProv,NULL,MS_STRONG_PROV,PROV_RSA_FULL,0);
CryptCreateHash(hProv,CALG_MD5,0,0,&hHash);
CryptHashData(hHash,(BYTE*)passwd,pwlen,0);
CryptDeriveKey(hProv,CALG_3DES,hHash,0,&hKey);
if(NULL != cyphertext && 0 != ptlen)
{
memcpy(cyphertext,plaintext,ptlen);
sz=*ctlen;
*ctlen=ptlen;
}
if(FALSE == CryptEncrypt(hKey,NULL,1,0,(BYTE *)cyphertext,ctlen,sz))
{
DWORD dwError = GetLastError();
if(ERROR_MORE_DATA == dwError)
{
dwSizeNeeded = *ctlen * sizeof(TCHAR);
}
}
CryptDestroyKey(hKey);
CryptDestroyHash(hHash);
CryptReleaseContext(hProv,0);
return dwSizeNeeded;
}
DWORD TripleDESdecrypt(TCHAR *cyphertext,DWORD ctlen,TCHAR *passwd,DWORD pwlen,TCHAR *plaintext,DWORD *ptlen)
{
HCRYPTPROV hProv;
HCRYPTHASH hHash;
HCRYPTKEY hKey;
DWORD dwSizeNeeded =0;
CryptAcquireContext(&hProv,NULL,MS_STRONG_PROV,PROV_RSA_FULL,0);
CryptCreateHash(hProv,CALG_MD5,0,0,&hHash);
CryptHashData(hHash,(BYTE *)passwd,pwlen,0);
CryptDeriveKey(hProv,CALG_3DES,hHash,0,&hKey);
if(*ptlen >= ctlen)
{
memcpy(plaintext,cyphertext,*ptlen);
CryptDecrypt(hKey,NULL,1,0,(BYTE *)plaintext,&ctlen);
*ptlen=ctlen;
}
else
{
dwSizeNeeded = ctlen * sizeof(TCHAR);
}
CryptDestroyKey(hKey);
CryptDestroyHash(hHash);
CryptReleaseContext(hProv,0);
return dwSizeNeeded;
}
int main()
{
HCRYPTPROV hCryptProv;
HCRYPTHASH hHash = 0;
HCRYPTKEY hKey = 0;
TCHAR szKey[] = _T("key");
TCHAR szUnencrypted[MAX_PATH * sizeof(TCHAR)] = _T("test");
TCHAR * pszEncrypted = NULL;
TCHAR * pszBase64 = NULL;
TCHAR * pszBase64Decoded = NULL;
TCHAR * psz3DESDecoded = NULL;
pszBase64 = Base64Encode((LPCBYTE)&szUnencrypted,_tcslen(szUnencrypted) * sizeof(TCHAR),FALSE);
DWORD dwEncryptedSize = _tcslen(pszBase64);
DWORD dwSizeNeeded = TripleDESencrypt(pszBase64,MAX_PATH * sizeof(TCHAR),szKey,_tcslen(szKey),pszBase64,&dwEncryptedSize);
pszEncrypted = new TCHAR[dwSizeNeeded];
TripleDESencrypt(pszBase64,MAX_PATH * sizeof(TCHAR),szKey,_tcslen(szKey),pszEncrypted,&dwEncryptedSize);
DWORD dwUnEncryptedSize = NULL;
dwSizeNeeded = TripleDESdecrypt(pszEncrypted,dwSizeNeeded,szKey,_tcslen(szKey),szUnencrypted,&dwUnEncryptedSize);
psz3DESDecoded = new TCHAR[dwSizeNeeded];
TripleDESdecrypt(pszEncrypted,dwSizeNeeded,szKey,_tcslen(szKey),psz3DESDecoded,&dwSizeNeeded);
pszBase64Decoded = Base64Decode(psz3DESDecoded,_tcslen(psz3DESDecoded) * sizeof(TCHAR));
MessageBox(NULL,0 == _tcscmp(pszBase64Decoded,szUnencrypted) ? _T("Strings Match"):_T("Strings do NOT Match"),_T(""),MB_OK);
delete [] pszBase64;
delete [] pszBase64Decoded;
delete [] pszEncrypted;
return 0;
}
I have tested it in both Unicode and ANSI and both seem to function as desired. You may want to clean my code up a bit.
Hope it helps,
-David Delaune
|
|
|
|
|
Hi David,
You have been a great help so far, by the way i have tested your code it works however I still need to do some tweaking as I can't convert "Zed5OmjUWs8=" to "test" and also what is this for:
ICryptoTransform cTransform = tdes.CreateDecryptor();
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
Thanks,
Jayjay
|
|
|
|
|
Hi,
Can any one please let me know the difference between OnPaint and OnDraw?
Regards,
KDevloper
|
|
|
|
|
OnDraw allows you to handle both painting and printing code in one place.It is available for CView.
If u put u'r code there then you u put nothing in OnPaint nor in OnPrint, since both of them will your code in OnDraw. just test use IsPrinting (CDocument member ? I do'nt remmebre).
Good luck.
|
|
|
|
|
Hi All,
I have a custom tree control.It doesnt have the ID.Im using the bellow code.
RECT rect = {25,29,190,250};
m_treeCtrl1.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|TVS_TRACKSELECT|TVS_SHOWSELALWAYS ,
rect,this, 1001);
Now I need to write the code in click event.It doesnt have the ID.so i dont know how to write the click event.
PLs help me..............
Thanks & Regars,
Anitha
|
|
|
|
|
AnithaSubramani wrote: It doesnt have the ID
Yes it does, it is the last argument of the Create function (so, it is 1001). In general it is better to reserve the ID in the resource file, so that when you add another control through the resource editor, the same Id won't be reused.
|
|
|
|
|
Thanks Cedric Moonen, I got the output.
|
|
|
|
|
Hi,
I made CListCtrl application which is used in column '0' checkboxes,column '1' comboboxes.when check combo will place,when you uncheck combo disappear.its working fine using onItemChanged() function.but problem is when user do double click check box becomes uncheck but combo placing in column '1' instead of disappear .am placing checkboxes dynamically using LVS_EX_CHECKBOXES.please help me in this.
Thanks & Regards,
T.Sreenivasa Chary.
|
|
|
|
|
Give code snipplet for the checkbox-change event handler, please.
|
|
|
|
|
Hi,
this the code snipplet.
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
int index=0;
int i;
index=pNMListView->iItem;
CStringList pComboList;
pComboList.AddTail("Sonu");
pComboList.AddTail("Sunny");
pComboList.AddTail("Cheechaa");
pComboList.AddTail("Srinu");
for(i=0;i < m_List.GetItemCount();i++)
{
bChecked=m_List.GetCheck(i);
CString strTemp;
strTemp.Empty();
strTemp.Format("%s",m_List.GetItemText(m_List.iRowIndex,1));
if(strTemp.IsEmpty())
{
if((i==m_List.iRowIndex) && (bChecked==1))
{
m_List.ShowInPlaceList(m_List.iRowIndex,1,pComboList,"");
//ShowinPlaceList is used for to place combo box
}
}
else
{
if(i==m_List.iRowIndex && bChecked==0) m_List.SetItemText(m_List.iRowIndex,1,"srinu");
}
}
*pResult = 0;
thanks & regards,
T.Sreenivasa Chary.
|
|
|
|
|
Where do you filter out the checkbox change? As i understood, you want the combo-box appear/disappear thing when the user checks or unchecks the checkbox of the list item. OnItemChange gets called also when the item's selection or focused state changes (and maybe some other cases i'm right now not aware of or am not thinking of). Should this code run for every possible state change?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
yes,the code change every possible state.when we check combo should appear,when we uncheck combo should not appear.in case double click checkboxes state becomes uncheck so combo should not appear but in my code when double click check box becomes uncheck its fine but combo appearing.pls solve my problem.
|
|
|
|
|
i want to find a control which looks like the msn's
it can display the gif dynamicly and the font ,can control the font size ,color and so on,it's best inherit from richtext ,any help is appreciated
regards
a beginner
|
|
|
|
|
Do you want to show images and fonts?
|
|
|
|
|
sure ,alos i need show the dynamic gif ,do u konw ,thanks
a beginner
|
|
|
|
|
You need to EnumFontFamily or EnumFontFamilies for enumerates fonts and CreateFont/ for images you can use of CImage class for load and show them.
|
|
|
|
|
Hello,
I am looking for information of present drives on the system.
I am interested to get information of each drive present on the system which includes -
1) Model,
2) Serial number,
3) Type
4) Solid state drive status, etc.
Now, I am able to get such information for hard disk's drives. But not able to get this information for other drives like CD-ROM, USB drives, etc.
I am using CreateFile method to locate that drive and pass the handle to DeviceIoControl method which gives me listed info for Hard disk drives only. The DeviceIoControl gives me blank buffer for other drives like CD_ROM and USB, etc.
I am using code to locate drive as -
HANDLE hDiskDevice = CreateFile(DeviceName,
GENERIC_READ| GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
To fetch information from the system, I am using -
DeviceIoControl(hDiskDevice,
SMART_RECEIVE_DRIVE_DATA,
pInputATABuffer,
InputBufferSize -1,
pOutputATABuffer,
OutputBufferSize -1,
&BytesReturned, NULL)
Please let me know if you have any ideas to get such information for USB, CD-ROM, etc drives.
Thank you.
With regards,
Shashikant
|
|
|
|
|
|
Did you see here[^]
Some things seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Hi,
can anyone please let me know what's the exact difference between subclasswindow and subclassdlgitem in subclassing?
Regards,
KDevloper
|
|
|
|
|
Looking at documentation, I suppose SubclassDlgItem is just a shortcut to the sequence
HWND hMyCtrl = GetDlgItem(IDC_MYCONTROL);
SubclassWindow( hMyCtrl );
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|