|
My only suggestion is to use your debugger, and follow the code down.
At some point, you'll see the code in CStatusBar return too early, and this will give you your problem.
That said, I'm surprised you're using SBPS_STRETCH for more than one pane. I thought that meant "take up all the rest of the space". And they can't all do that! Maybe the panes are too busy engaged in a tug of war to pay attention to you?
Iain.
|
|
|
|
|
Hi all,
Is there a c++ version of this or at least can a c++ version of this algorithm can be made? Please advise. Can anyone give me a sample on how to use windows crypto api decryption just by inputting an encrypted string?
Thanks,
Jayjay
btw this is made of c#
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);
}
modified on Thursday, November 20, 2008 3:28 AM
|
|
|
|
|
|
Hi Randor,
Thanks btw this is the encrypt code from where the string passed is derived:
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);
}
|
|
|
|
|
Randor wrote: Hope it helps!
If it doesn't, it is not your fault, for sure.
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]
|
|
|
|
|
Bonjour David,
I am a bit confused should I use CryptBinaryToString or CryptStringtoBinary?
Thanks,
Jayjay
|
|
|
|
|
Use CryptStringToBinary to decode from base64.
Use CryptBinaryToString to encode to base64.
Best Wishes,
-David Delaune
|
|
|
|
|
Hi,
I did a translation test and here it is unfortunately it ends up garbage:
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;
BYTE * value2 = {0};
DWORD lul_len, lul_buflen, lul_skip, lul_pflags;
bool lb_rtn;
BLOB lblob_data;
TCHAR convertedStr[13];
convertedStr[0] = ('\0');
BYTE key1[24] = {0};
lul_len = 13;
lul_buflen = (lul_len * 2);
std::string value = "Zed5OmjUWs8=";
hProv = InitializeCrypt();
bool result = CryptStringToBinary(value.c_str(), lul_len, CRYPT_STRING_BASE64, key1, &lul_buflen, &lul_skip, NULL);
result = CryptCreateHash(hProv,CALG_MD5,0,0,&hHash);
result = CryptDeriveKey(hProv,CALG_3DES,hHash,0,&hKey);
memcpy(plaintext,key1,*ptlen);
result = CryptDecrypt(hKey,NULL,1,0,plaintext,&ctlen);
*ptlen=ctlen;
result = CryptDestroyKey(hKey);
result = CryptDestroyHash(hHash);
result = CryptReleaseContext(hProv,0);
}
int main() {
HCRYPTPROV hCryptProv;
HCRYPTHASH hHash = 0;
HCRYPTKEY hKey = 0;
PBYTE pbBuffer = NULL;
DWORD dwCount;
const BYTE * value;
DWORD lul_len, lul_buflen, lul_skip, lul_pflags, ptlen;
bool lb_rtn;
BLOB lblob_data;
std::string key = "h3bmull3r";
const std::string s = "Zed5OmjUWs8=" ;
value = reinterpret_cast<const BYTE *>(s.c_str());
int stringSize = s.size();
TCHAR convertedStr[12];
convertedStr[0] = ('\0');
lul_len = s.size();
lul_buflen = (lul_len * 2);
char CypherText[128]="Zed5OmjUWs8=";
char MyPassword[]="h3bmull3r";
unsigned char MyString[128];
unsigned long len1,len2,len3;
len1=strlen(CypherText);
len2=strlen(MyPassword);
len3=128;
memset(MyString,0,128);
len1=128;
lb_rtn = CryptBinaryToString(value, lul_len, CRYPT_STRING_BASE64, convertedStr, &lul_buflen);
ThreeDESdecrypt((unsigned char *)CypherText,len3,(unsigned char *)MyPassword,len2,(unsigned char *)MyString,&len1);
return 0;
}
The bold part CryptDecrypt returns false and the plaintext is garbage, What I expect the plaintext to contain "test".
The thing is this is the code that encrypts test:
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);
}
That is the service that sends me the encrypted string which i need to decrypt I tested "test" as my string and I get "Zed5OmjUWs8=" as the encrypted string. also the key being used as the security key is "h3bmull3r"
Please advise.
merci,
Jayjay
modified on Friday, November 21, 2008 4:59 AM
|
|
|
|
|
monsieur_jj wrote: Is there a c++ version of this
Possibly, yes.
monsieur_jj wrote: or at least can a c++ version of this algorithm can be made?
This for sure, even the C# one is, at the end, done in C++ .
Reference about Crypto API here. There are also articles about, here at CodeProject [^].
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]
|
|
|
|
|
|
Hi all,
I am using CListCtrl with Report view in my module.
I have 4 columns in it.
I want to change only a particular cell in second column but not the
entire column or the row corresponding to that cell.
I am unable to do it properly with InsertItem and SetItemText.I need to change the entire column or entire row if I use these functions.
How can I do it?
Regards,
Sunil Kumar
|
|
|
|
|
Can you show your code how did you try?
|
|
|
|
|
actually the setitemtext() works fine.
i u dont know, the subitem argument of the setitemtext() is actually the column identifier.
the first column is subitem = 0 and so on
|
|
|
|
|
sunilkumar.d wrote: I am unable to do it properly with InsertItem and SetItemText.
Why not SetItemText?
|
|
|
|
|
Do I need to use InsertItem along with SetItemText even
to change a single cell value.?
Or directly I can use SetItemText(2, 1,"hello") to change second row 1st column?
Regards,
Sunil Kumar
|
|
|
|
|
You cannot set a value to a cell if that row is not inserted yet.
|
|
|
|
|
yeah that is true, but if the row is already inserted, then
just I want to change one cell value in that row.
So I need to insert it again.
Regards,
Sunil Kumar
|
|
|
|
|
In that case you don't have to insert again... What is happening if you just call the SetItemText only?
|
|
|
|
|
I dont see any effect if I call SetItemText.
Regards,
Sunil Kumar
|
|
|
|
|
Could you please post relevant code parts?
|
|
|
|
|
Hi All
How can i get Document path in vista?I am useing
TCHAR szPath[MAX_PATH];
if(SUCCEEDED(SHGetFolderPath(NULL,
CSIDL_MYDOCUMENTS|CSIDL_FLAG_CREATE,
NULL,
0,
szPath1)))
{
PathAppend(szPath1, _T("abc.txt"));
}
But CSIDL_MYDOCUMENTS it's not working in Vista.So i have also use this CSIDL_COMMON_DOCUMENTS.But result is different. I am geting this path
D:\Users\Public\Documents when i am uesing CSIDL_COMMON_DOCUMENTS.
But i want to find this this path
D:\Users\SystemName\Documents .
Plz help me.
|
|
|
|
|
What do you want? The path of "My Documents" folder of the present user? What do you mean by "not working"?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Thanks for reply
in vista no My Documents folder present only Document folder present. And i want to get Document folder of present user.
What do you mean by "not working"?
I mean when i use CSIDL_MYDOCUMENTS then i am geting null values.
|
|
|
|
|
Try this:
TCHAR szPath[MAX_PATH];
if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, szPath)))
AfxMessageBox(szPath);
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Problem solved with this CSIDL_PERSONAL.
|
|
|
|
|