Click here to Skip to main content
15,921,941 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to access application's extern variable inside a dll Pin
rahul.kulshreshtha16-Dec-11 5:46
rahul.kulshreshtha16-Dec-11 5:46 
AnswerRe: How to access application's extern variable inside a dll Pin
Erudite_Eric16-Dec-11 0:40
Erudite_Eric16-Dec-11 0:40 
GeneralRe: How to access application's extern variable inside a dll Pin
rahul.kulshreshtha16-Dec-11 3:53
rahul.kulshreshtha16-Dec-11 3:53 
AnswerRe: How to access application's extern variable inside a dll Pin
Chris Losinger16-Dec-11 4:16
professionalChris Losinger16-Dec-11 4:16 
GeneralRe: How to access application's extern variable inside a dll Pin
rahul.kulshreshtha16-Dec-11 5:22
rahul.kulshreshtha16-Dec-11 5:22 
GeneralRe: How to access application's extern variable inside a dll Pin
Richard MacCutchan16-Dec-11 7:04
mveRichard MacCutchan16-Dec-11 7:04 
GeneralRe: How to access application's extern variable inside a dll Pin
Chris Losinger16-Dec-11 8:03
professionalChris Losinger16-Dec-11 8:03 
GeneralRe: How to access application's extern variable inside a dll Pin
Richard MacCutchan16-Dec-11 22:42
mveRichard MacCutchan16-Dec-11 22:42 
QuestionWhich function can I use instead of ShowControlBar Pin
adityarao3115-Dec-11 19:42
adityarao3115-Dec-11 19:42 
AnswerRe: Which function can I use instead of ShowControlBar Pin
Resmi Anna15-Dec-11 21:45
Resmi Anna15-Dec-11 21:45 
QuestionDES Encryption Pin
jkirkerx15-Dec-11 19:12
professionaljkirkerx15-Dec-11 19:12 
SuggestionRe: DES Encryption Pin
Code-o-mat15-Dec-11 22:20
Code-o-mat15-Dec-11 22:20 
GeneralRe: DES Encryption Pin
jkirkerx16-Dec-11 6:40
professionaljkirkerx16-Dec-11 6:40 
GeneralRe: DES Encryption Pin
Code-o-mat16-Dec-11 7:01
Code-o-mat16-Dec-11 7:01 
AnswerRe: DES Encryption Pin
Richard MacCutchan15-Dec-11 23:40
mveRichard MacCutchan15-Dec-11 23:40 
AnswerRe: DES Encryption Pin
Richard MacCutchan16-Dec-11 1:16
mveRichard MacCutchan16-Dec-11 1:16 
GeneralRe: DES Encryption Pin
jkirkerx16-Dec-11 7:19
professionaljkirkerx16-Dec-11 7:19 
GeneralRe: DES Encryption Pin
Richard MacCutchan16-Dec-11 7:40
mveRichard MacCutchan16-Dec-11 7:40 
GeneralRe: DES Encryption Pin
Randor 16-Dec-11 7:59
professional Randor 16-Dec-11 7:59 
GeneralRe: DES Encryption Pin
jkirkerx16-Dec-11 8:12
professionaljkirkerx16-Dec-11 8:12 
GeneralRe: DES Encryption Pin
jkirkerx16-Dec-11 9:00
professionaljkirkerx16-Dec-11 9:00 
GeneralRe: DES Encryption Pin
Randor 16-Dec-11 9:41
professional Randor 16-Dec-11 9:41 
GeneralRe: DES Encryption Pin
jkirkerx16-Dec-11 10:31
professionaljkirkerx16-Dec-11 10:31 
GeneralRe: DES Encryption Pin
Randor 16-Dec-11 11:04
professional Randor 16-Dec-11 11:04 
GeneralRe: DES Encryption Pin
jkirkerx16-Dec-11 12:06
professionaljkirkerx16-Dec-11 12:06 
I went back to what I had before I posted, and changed CALG_DES to CALG_MD5. I don't get an error, , I'm just struggling in making my buffer that passes in/out in CryptEncrypt.

I get a value back that's sort or weird. It works, but I think the size of my buffer is too large.

R㏾΂ò.¢Ó`Ï­<oÝV|63¾ˆWãÔZ÷(šœ(è~Ó¥¶ãòõ¬"oÌtðaÏMûÏþƒÝÌXðýýýý««««««««îþîþîþîþîþîþ

I think the end in bold is a leak somewhere, or the buffer being too large

I know I need to CryptEncrypt once to get the buffer size, and do it again for the real thing.

I did a conversion to UTF8, that I think I need to dump. I'm going to dump it, and work on the buffer sizing.

This is what I had before I posted, with the one small change. It's not bad considering I had no clue what to do, but it's all I need, with the base64 at the end of the gig.

WCHAR*	CA_Encryption::_encrypt_DES( WCHAR *pzInput )
{
	BOOL			bResult = FALSE;
	WCHAR			*szOutput = NULL;

	DWORD cbKey64	= sizeof(KEY_64);
	HCRYPTPROV		hProv;
	HCRYPTHASH		hHash = NULL;
	HCRYPTKEY		hKey = NULL;

	const int		DES_SIZE = 64;
	static BYTE		hash[DES_SIZE];
	DWORD			buffer_size = sizeof(hash);
	DWORD			buffer_length;		

	// Get the size of the conversion
	int iChar = WideCharToMultiByte(CP_UTF8, 0, pzInput, -1, NULL, 0, NULL, NULL);	
	char *szInput = new char[iChar];
	WideCharToMultiByte(CP_UTF8, 0, pzInput, -1, szInput, iChar, NULL, NULL);
	
	// Aquire a handle the Encryption provider
	bResult = CryptAcquireContextW( &hProv, 0, MS_STRONG_PROV, PROV_RSA_FULL, 0);
	bResult = CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash);
	bResult = CryptHashData(hHash, KEY_64, sizeof(KEY_64), 0);	
	bResult = CryptDeriveKey(hProv, CALG_DES, hHash, 0, &hKey);
	bResult = CryptSetKeyParam(hKey, KP_IV, IV_64, 0);

	// Get the size of the buffer
	buffer_length = strlen((char *)szInput);	
	BYTE *szBuffer = new BYTE[64];
	memcpy( szBuffer, (BYTE*)szInput, sizeof(szInput) );
	delete [] szInput;

	// Get the size of the hash and length
	bResult = CryptEncrypt(hKey, 0, FALSE, 0, szBuffer, &buffer_size, buffer_length);	
	
			
	CryptDestroyKey(hKey);
	CryptDestroyHash(hHash);
	CryptReleaseContext(hProv, 0);	
	
	return szOutput;
}


This is what I'm trying to copy from asp.net

VB
Public Shared Function Encrypt(ByVal value As String) As String
        If value <> "" Then
            Dim cryptoProvider As DESCryptoServiceProvider = New DESCryptoServiceProvider()
            Dim ms As MemoryStream = New MemoryStream()
            Dim cs As CryptoStream = New CryptoStream(ms, cryptoProvider.CreateEncryptor(KEY_64, IV_64), _
            CryptoStreamMode.Write)
            Dim sw As StreamWriter = New StreamWriter(cs)

            sw.Write(value)
            sw.Flush()
            cs.FlushFinalBlock()
            ms.Flush()

            'convert back to a string
            Return Convert.ToBase64String(ms.GetBuffer(), 0, ms.Length)
        Else
            Encrypt = ""
        End If

    End Function

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.