|
I’m not sure what exactly you’re really trying to do, but for information on sending messages here is an excellent article
http://www.codeproject.com/dialog/messagemgmt.asp[^]
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
|
|
|
|
|
Bravoone_2006 wrote: i want to Broadcast a message to multiple instances of an application !
Use WM_COPYDATA .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hello,
I am trying to encrypt some data which contains a structure and the encrypted data looks like the following
ËO.ÛßÞ¸ëô'¾óÉïD»åÏë3¸·««««««««"
The code to encrypt the data is the following
dwBufferLen = dwCount=((STRUCT_BUF)pBufPtr)->ulSize;
if(!CryptEncrypt(hKey, 0, TRUE, 0,pBufPtr, &dwCount, dwBufferLen))
{
if(GetLastError() == ERROR_MORE_DATA)
{
//MessageBox("error","",MB_OK);
}
}
Now I want to convert this encrypted data to a string so that it can be displayed to the user on the screen for typing purposes
However when I call CryptBinaryToString with the data passed in it returns a string with alphanumeric characters but also other garbage characters. The string looks like the following
y08u29/euOv0vWzx9Oo
DWORD len;
if(!CryptBinaryToString(pBufPtr,dwCount,1,NULL,&len))
{
DWORD dwRet;
dwRet=GetLastError();
MessageBox("error","",MB_OK);
}
char *msg2=(char*)malloc(len);
*msg2 = NULL;
if(!CryptBinaryToString((BYTE *)pBufPtr,dwCount,1,msg2,&len))
{
DWORD dwRet;
dwRet=GetLastError();
}
Instead of 1 as the third argument above I tried passing in 4 and 12 but still get the same result. So how do I get rid of the garbage characters. Please help.
Thanks.
vg
|
|
|
|
|
vgandhi wrote: Instead of 1 as the third argument above I tried passing in 4 and 12 but still get the same result
Where are you getting those numbers from?
The third argument should be one of the following, correct?
CRYPT_STRING_BASE64HEADER
CRYPT_STRING_BASE64
CRYPT_STRING_BINARY
CRYPT_STRING_BASE64REQUESTHEADER
CRYPT_STRING_HEX
CRYPT_STRING_HEXASCII
CRYPT_STRING_BASE64_ANY
CRYPT_STRING_ANY
CRYPT_STRING_HEX_ANY
CRYPT_STRING_BASE64X509CRLHEADER
CRYPT_STRING_HEXADDR
CRYPT_STRING_HEXASCIIADDR
I suppose CRYPT_STRING_HEXASCII is the human-readable one.
Mark
|
|
|
|
|
Basically 1 stands for CRYPT_STRING_BASE64 and 4 stans for CRYPT_STRING_HEX
CRYPT_STRING_HEXASCII doesn't help in this case also.
Thanks
vg
|
|
|
|
|
This works for me with no garbage chars...
BYTE BinaryBytes[256];
for (int i = 0; i < 256; ++i)
BinaryBytes[i] = (BYTE)i;
DWORD dwStrLen = 0;
::CryptBinaryToString(BinaryBytes, 256, CRYPT_STRING_HEXASCII, NULL, &dwStrLen);
LPTSTR pszBuf = new TCHAR[dwStrLen];
::CryptBinaryToString(BinaryBytes, 256, CRYPT_STRING_HEXASCII, pszBuf, &dwStrLen);
delete[] pszBuf;
|
|
|
|
|
Dear Mark,
Yes this worked for you but if you see the string value in this case how will you display it to the user. It is not in any displable format whereas I want to display the data on the screen for the user to either type or read it loud. Thanks.
vg
|
|
|
|
|
What are you expecting to see?
The source is bytes, 0 to 255. How do you want to represent them on the screen?
You can always loop through the source bytes and convert them to whatever format you want.
Mark
|
|
|
|
|
Why are you calling that garbage? You're passing the flag 1, which is CRYPT_STRING_BASE64 , and you're getting back a base 64 encoded version of the data.
|
|
|
|
|
Dear Mike,
The string that I get from the CryptBinarytoString has a square shaped ascii character in it and that gets displayed to the user that day. So if the user were to use that string there is no way he/she can do that. I'm getting a base 64 encoded version of the data but I'm just wondering as to why it always includes those funny characters at the end and is there a way to avoid it.
Thanks.
vg
|
|
|
|
|
This code works for me:
int main()
{
LPCSTR data = "Some encrypted data goes here...";
LPTSTR pszBase64 = NULL;
DWORD cchString = 0;
CryptBinaryToString ( (const BYTE*) data, strlen(data), CRYPT_STRING_BASE64, NULL, &cchString );
pszBase64 = (LPTSTR) _alloca ( cchString * sizeof(TCHAR) );
CryptBinaryToString ( (const BYTE*) data, strlen(data), CRYPT_STRING_BASE64, pszBase64, &cchString );
wcout << pszBase64 << endl;
return 0;
} I get the output:
U29tZSBlbmNyeXB0ZWQgZGF0YSBnb2VzIGhlcmUuLi4=
|
|
|
|
|
Yes but you using a string instead of a byte buffer. So try this out
typedef unsigned char *PBYTE;
typedef struct chal_buffer
{
DWORD ulSize; // size of the entire structure
DWORD Num1;
}CHALL_BUF, *PCHALL_BUF;
PBYTE pBufPtr
pBufPtr = (UCHAR*)malloc(sizeof(CHALL_BUF));
if(!pBufPtr)
return;
((PCHALL_BUF)pBufPtr)->ulSize = sizeof(CHALL_BUF);// in bytes
((PCHALL_BUF)pBufPtr)->Num1=1233456;
if(!CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, 0))
{
if(GetLastError() != NTE_BAD_KEYSET)
{
}
if(!CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_NEWKEYSET))
{
}
}
if(!CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash))
{
DWORD dwRet = GetLastError();
}
// Derive a session key from the hash object.
if(!CryptDeriveKey(hProv, CALG_RC4, hHash, 0, &hKey))
{
DWORD dwRet = GetLastError();
}
// Destroy the hash object.
CryptDestroyHash(hHash);
hHash = 0;
dwBufferLen = dwCount=((PCHALL_BUF)pBufPtr)->ulSize;
if(!CryptEncrypt(hKey, 0, TRUE, 0,pBufPtr, &dwCount, dwBufferLen))
{
if(GetLastError() == ERROR_MORE_DATA)
{
//MessageBox("error","",MB_OK);
}
}
DWORD len = 0;
if(!CryptBinaryToString(pBufPtr,dwCount,CRYPT_STRING_BASE64,NULL,&len))
{
DWORD dwRet;
dwRet=GetLastError();
MessageBox("error","",MB_OK);
}
LPTSTR pszBase64 = NULL;
pszBase64 = (LPTSTR) _alloca ( len * sizeof(TCHAR) );
if(!CryptBinaryToString((BYTE *)pBufPtr,dwCount,CRYPT_STRING_BASE64,pszBase64,&len))
{
DWORD dwRet;
dwRet=GetLastError();
}
vg
|
|
|
|
|
What are you expecting to see? CryptBinaryToString() only understands BYTEs as input so whether
you input a char string or a byte buffer is irrelevant.
A byte has 256 values. That means that somehow CryptBinaryToString() must be able to represent
256 values with a limited set of ASCII characters.
Again, what do you want to see? Maybe that API isn't appropriate for your needs.
Mark
|
|
|
|
|
Dear Mark,
I basically want to convert each byte in the encrypted data into two hexidecimal characters. For example 'z' becomes 7A. However my encrypted data is not of fixed length so I'm not sure how do to this.
Also once I have the hexidecimal character encrypted data I also need to convert it back into the encrypted data. So that is the functionality I'm looking for.
So any suggestions.
Thanks.
vg
|
|
|
|
|
Ok, I'm with you. I think the CryptBinaryToString(() API was meant more for converting binary
into characters that can be used in HTML/XML/etc. Not necessarily to be human-readable.
The problem is that in the encrypted data there's no 'z'. There's just bytes.
You'll need to store the length somehow. An easy way is to reserve the first BYTE/WORD/DWORD
to hold the length of the following encrypted data.
With the length, you can loop through the encrypted bytes, converting each to hex and
appending to a string.
I'm not sure about converting it back to encrypted though. If you allow the user to make
changes then the data won't be able to be unencrypted later.
It doesn't make sense really anyway - how can a user understand encrypted data?
Mark
|
|
|
|
|
hi every one
i have a single document project that inheritored from CFormViwe
i add one Dialog with one Button ,and in OnCreate CMainFram Create one DialogBar.
if (!m_wndDlgBar.Create(this, IDD_DIALOGBAR,<br />
CBRS_LEFT|CBRS_TOOLTIPS|CBRS_FLYBY, IDD_DIALOGBAR))<br />
{<br />
TRACE0("Failed to create DlgBar\n");<br />
return -1;
}
Then create BN_CLICKED message in CMainframe.
my button work corectly.
now i create one class for mydialogBar and write my code in OnInitUpdate or OnDraw
But it can not be run.
Please Help Me.
|
|
|
|
|
samira samehforooghy wrote: now i create one class for mydialogBar
Which derives from ??
samira samehforooghy wrote: and write my code in OnInitUpdate or OnDraw
Why you want to write this code there ?
There will mulitple calls to above code.
|
|
|
|
|
hi
prasad_som wrote: Which derives from ??
CDialog
whats the mean of mulitple
With special thanks
|
|
|
|
|
I asked about dialog bar class. Does it derive from CDialogBar .
What about my second question asked previously.
|
|
|
|
|
how to access CMOS RAM?
can any body help me in this.
pavan
|
|
|
|
|
Hi
All
I want to read value in string table in resource dll in VC++ 6.0. I want to call value in string table in Dll to another application. If anybody have solution to this plz send me.
Thanks in advance.
Atool
|
|
|
|
|
M. Atul wrote: I want to read value in string table in resource dll in VC++ 6.0. I want to call value in string table in Dll to another application.
Use LoadLibrary and LoadString.
M. Atul wrote: If anybody have solution to this plz send me.
Read this[^] too. Point number 2.
|
|
|
|
|
Hi All!
When in a simple project, I add a control activeX in a dialogue box it work perfectly, however when i make the dialog box (containing the activeX) in a dll (MFC DLL), i get nothing (no dialog box and consequently no activeX). When i remove the activeX control, the dialog box can be displayed!
my question is so how to add a activex control in a dll?
Thank u in advance.
Nirmal
|
|
|
|
|
I think the problem lies with the resource file being used.. As the dialogue template is in your DLL, where as your main app searches the template in its own resources and consequently dont find anything .. Try using the dll's resources .. try using the FindResource(..) function and then creating the dialogue from the template returned by the function .. I hope it helps enjoy.
|
|
|
|
|
I would ask this question on the algorithms/maths board, but I feel it is more appropriate here.
Lets say I have 2 points, { X1,Y1 } and { X2,Y2 }, I want to calculate the rotation of #2 around #1 given a number of degrees. What is the fasted possible way to do this in C++?
Here is my method, which I find to be too slow.
X2 = X1 * cosf(rotate) - Y1 * sinf(rotate);<br />
Y2 = X1 * sinf(rotate) + Y1 * cosf(rotate);
|
|
|
|