|
As I suspected, szOutput is an auto (i.e., local) variable. Under the right conditions, it will point to szBase64 , another auto variable. It sounds as though you need to call _encrypt_3DES() with an additional argument: a buffer to store the result in.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Thanks for checking it out Dave.
I even experimented with changing the name of szOutput to unique names, but it still did the same thing.
I think that's why all the examples I saw had the base64 part in a separate function.
|
|
|
|
|
Thanks for your help. You were right on the money.
I learned alot on this one. Sort of like the post above this one. When you allocate memory, you have to have the exact right size including the null terminator.
So now I call it twice, once to get the size I need, and again with the right size.
I still have 1 bug left, I get 2 extra spaces in the SQL database column that are squares, I may have double null terminators or something. The -2 was just an experiment.
DWORD dwSecretAnwser;
caEncrypt._encrypt_3DES(szSecretAnwser, dwSecretAnwser);
WCHAR *szSecretAnwser_Secure = new WCHAR[dwSecretAnwser];
szSecretAnwser_Secure = caEncrypt._encrypt_3DES(szSecretAnwser, dwSecretAnwser);
WCHAR* CA_Encryption::_encrypt_3DES( WCHAR *pzInputW, DWORD &dwOutput )
{
BOOL bResult = FALSE;
HCRYPTPROV hProv;
HCRYPTKEY hKey;
ALG_ID Algid;
PBYTE pbKeyBlob = NULL;
BYTE *pbBuffer;
DWORD dwBlockLen = 0;
DWORD dwDataLen = 0;
DWORD cbData;
BOOL bFinal = TRUE;
DWORD errorCode = 0;
TCHAR *szBase64 = NULL;
DWORD dwResult;
DWORD cbKeyLen = sizeof(KEY_192);
int iCharA = (WideCharToMultiByte(CP_UTF8, 0, pzInputW, -1, NULL, 0, NULL, NULL) - 1);
char *szInputA = new char[iCharA];
WideCharToMultiByte(CP_UTF8, 0, pzInputW, -1, szInputA, iCharA, NULL, NULL);
keyBlob192.hdr.bType = PLAINTEXTKEYBLOB;
keyBlob192.hdr.bVersion = CUR_BLOB_VERSION;
keyBlob192.hdr.reserved = 0;
keyBlob192.hdr.aiKeyAlg = CALG_3DES;
keyBlob192.cbKeySize = sizeof(KEY_192);
CopyMemory(keyBlob192.rgbKeyData, KEY_192, cbKeyLen> sizeof(keyBlob192) ? sizeof(keyBlob192) : cbKeyLen);
bResult = CryptAcquireContextW( &hProv, 0, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
bResult = CryptImportKey(hProv, (BYTE*)&keyBlob192, sizeof(keyBlob192), 0, CRYPT_EXPORTABLE, &hKey);
bResult = CryptSetKeyParam(hKey, KP_IV, IV_192, 0);
dwDataLen = sizeof(ALG_ID);
cbData = iCharA;
if (!CryptGetKeyParam(hKey, KP_ALGID, (BYTE *)&Algid, &dwDataLen, 0))
return 0;
if (GET_ALG_TYPE(Algid) != ALG_TYPE_STREAM) {
dwDataLen = sizeof(DWORD);
if (!CryptGetKeyParam(hKey, KP_BLOCKLEN, (BYTE *)&dwBlockLen, &dwDataLen, 0))
return 0;
dwDataLen = ((cbData + dwBlockLen - 1) / dwBlockLen) * dwBlockLen;
if (!(pbBuffer = (BYTE *)LocalAlloc(LMEM_FIXED, dwDataLen)))
return 0;
}
else {
if (!(pbBuffer = (BYTE *)LocalAlloc(LMEM_FIXED, cbData)))
return 0;
}
CopyMemory(pbBuffer, szInputA, cbData);
if (!CryptEncrypt(hKey, 0, bFinal, 0, pbBuffer, &cbData, dwDataLen)) {
LocalFree(pbBuffer);
return 0;
}
SecureZeroMemory( keyBlob192.rgbKeyData, sizeof(keyBlob192.rgbKeyData) );
delete [] szInputA;
CryptDestroyKey(hKey);
CryptReleaseContext(hProv, 0);
if(CryptBinaryToString((BYTE*)pbBuffer, cbData, CRYPT_STRING_BASE64, NULL, &dwResult)) {
if ((dwOutput > 0 ) && (dwOutput < 4096)) {
szBase64 = new TCHAR[dwResult];
CryptBinaryToString((BYTE*)pbBuffer, cbData, CRYPT_STRING_BASE64, szBase64, &dwResult);
dwOutput = dwResult;
szBase64[dwResult-2] = 0;
return szBase64;
}
else {
dwOutput = dwResult;
return L'\0';
}
}
else {
dwOutput = dwResult;
return L'\0';
}
}
|
|
|
|
|
Hi,
Does anyone know of a compiler that will run under Windows 7 (64 bit) but will compile 16 bit DOS based code? I used to use MSVC 1.52 on XP 32 bit but it will not run on a 64 bit platform. I tried running it under Virtual PC but it is too unstable (it regularly deleted the contents of my source files which is not much fun).
Thanks
|
|
|
|
|
A quick search gives promising results for running Turbo C using DOSBox : I've not tried that, however.
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]
|
|
|
|
|
I don't often use Windows 7 so I might be wrong on this, but as far as I know it comes with a built in 32 bit Windows XP virtual machine? MSVC 1.52 might work in that.
Personally I use Microsoft C 6.0 in DosBox[^] and MSVC 1.52 in a Windows 2000 guest OS with VirtualBox[^], both works.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
Thanks for the reply.
Win 7/64 Pro does come with XP virtual machine but unfortunately I only have the Home edition which does not. I thought about upgrading but its too much hassle re-installing everything.
I have a copy of Microsoft C 6.0 somewhere so I think I will give that a go in DosBox.
Can you advise how I install it in DosBox please.
Thanks for the tip.
|
|
|
|
|
You can download the VM from here[^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
softwaremonkey wrote: I thought about upgrading but its too much hassle re-installing everything.
Upgrading from Home 7 to Pro 7 does not require you to reinstall a thing. All it does, essentially, is replace what's in the Windows folder with the upgraded components, and leave the registry and all program files intact.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi Richard,
Thanks for this info. This only applies if you buy the Windows 7 Anytime Upgrade. Even though I have a copy of Windows 7 professional, it will not perform the upgrade - unless anyone knows differently.
Thanks again
Tony
modified 23-Dec-11 11:51am.
|
|
|
|
|
Your Product key from your boxed Pro 7 will work as an Anytime Upgrade key. I did that myself on a new netbook I had purchased with Win 7 Starter.
I chose the Anytime Upgrade, and put in my boxed Win 7 product key, and everything went through.
So you're not out of luck.
Rich
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Try [Microsoft QuickC 16 Bit] IDE/Compiler for the C programming language. Its main competitor was Turbo C. (Quick C vs Turbo C , get it? ), Its from the year 1990.
[This] link mentions this:
Emulation
The easiest way to get Turbo C/C++ to run is using DOSBOX which emulates the environment of an old 16bit MsDOS computer. This works very well and will allow you to run most programs (even CGA/VGA/SVGA graphics).
If you wish to run Turbo C on Linux there is DOSEMU.
Virtualization
Another option is to run the programs on a Virtual Machine. Think of this as running a virtual computer on your computer. The VM emulates a PC and you can load an OS like an old copy of windows (if you have old disks laying about) or you can use FreeDOS as an OS.
|
|
|
|
|
Thanks for the reply.
As I said earlier, I have used Microsoft Virtual PC and loaded Windows XP 32 bit on it but it was very slow and routinely locked up and lost connection to the host HDD, loosing the contents of any source file I had made changes to
Since them I have installed Oracle VM Virtual Box which seems (so far) to be a much better product.
Thanks again
Tony
|
|
|
|
|
I create MFC application and run its exe on a system where .net is not installed.
What dll i need to copy on new system.
|
|
|
|
|
|
Hi All,
I want to capture screen of dialog and save it in JPEG format in MFC application.
Does anybody have sample code in VC++ for this?
Thanks in advance.
-Amit
|
|
|
|
|
Check if this link will help you <barry's screen="" capture<="" a="">[^]
Every new day is another chance to change your life.
|
|
|
|
|
Hi Chandrasekharan P,
I already have code to capture screen in BMP format.
I want to capture screen in JPEG format.
if you have VC++ code please share it to me.
Thanks in advance.
-Amit
|
|
|
|
|
Use GDI+.
The Image::Save[^] method allows you specify the jpeg file type.
Independent ACN Business Owner- Check out the possibilities for your future!
- Financial independance
- Full time or Part time
- In more than 20 countries through North America, Europe, Asia and the Pacific
- Featuring the ACN IRIS 5000 video phone. See the person you are talking to.
Within you lies the power for good - Use it!
|
|
|
|
|
Thanks all for feedback.
I am new in VC++ MFC programming.
In my application, User presses show dialog button. Then dialog window gets opend. Here after opening dialog I want to save dialog screenshot in. JPEG format to any local folder. Does anybody have sample code? Please help me.
-Amit
|
|
|
|
|
Hi All,
I have got the solution.
Thanks all for help.
-Amit
|
|
|
|
|
Hello all. I'm trying to synthesize alt + space to bring up the output window's menu using SendInput(). For some reason it works on other windows that I click on after compiling, but CMD windows just take it as a space key press. Here's what I have:
Sleep(2500);
INPUT in1 = {INPUT_KEYBOARD};
INPUT in2 = {INPUT_KEYBOARD};
INPUT in3 = {INPUT_KEYBOARD};
INPUT in4 = {INPUT_KEYBOARD};
KEYBDINPUT k1 = {VK_MENU,0,0,0,0};
KEYBDINPUT k2 = {VK_SPACE,0,0,0,0};
KEYBDINPUT k3 = {VK_SPACE,0,KEYEVENTF_KEYUP,0,0};
KEYBDINPUT k4 = {VK_MENU,0,KEYEVENTF_KEYUP,0,0};
in1.ki = k1;
in2.ki = k2;
in3.ki = k3;
in4.ki = k4;
SendInput(1, &in1, sizeof(INPUT));
SendInput(1, &in2, sizeof(INPUT));
SendInput(1, &in3, sizeof(INPUT));
SendInput(1, &in4, sizeof(INPUT));
system("pause");
So this works in other windows and ignores the alt press in CMD windows. Snarl. The alt + space hot key works in CMD windows when I press the keys manually.
|
|
|
|
|
Just a guess but it could be that the key handler for those windows you want to target use GetKeyState[^] or GetAsynchKeyState[^] to check if the ALT key is down or not and SendInput does not change what these will return. I guess you could test for this by manually pressing the ALT key and sending the space with SendInput as you do.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
I try to compile my project with "Maximize speed /o2"
But when i compile i get:
Command line error D8016 : /o2 and /RTC1 command line options are incompatible
Any one know what can i do about it?
Thanks
|
|
|
|
|
you'll need to disable the "run time error checks" compiler option.
|
|
|
|
|