How to invoke the WinApi method "CryptProtectData" ?

558 views
Skip to first unread message
Message has been deleted

brainman

unread,
Mar 4, 2013, 3:41:30 AM3/4/13
to golan...@googlegroups.com
Check that CryptProtectData returned successfully. Also, you must release output buffer with LocalFree as per api.

Alex

brainman

unread,
Mar 5, 2013, 1:44:45 AM3/5/13
to golan...@googlegroups.com
I changed your program http://play.golang.org/p/fD7mx2k4Yc to fix some small errors. But I get same result as you are. I have never used

CryptProtectData before, so I do not know what our mistake is. Perhaps you should ask a windows expert. Sorry.

Alex

John Doe

unread,
Mar 5, 2013, 10:25:36 PM3/5/13
to golan...@googlegroups.com
Makes me thing this is Golang specific, invoking the method (and the equivalent decrypt method) from VC++ worked flawlessly ..

brainman

unread,
Mar 5, 2013, 10:38:34 PM3/5/13
to golan...@googlegroups.com
 It is sure possible something to do with Go. Send me your non-Go program to compare. I will investigate when I have time. Thank you.

Alex

John Doe

unread,
Mar 6, 2013, 12:28:15 AM3/6/13
to golan...@googlegroups.com
Thank you for taking the time.
Here is the snippet: http://pastebin.com/gLyHrrP0

brainman

unread,
Mar 6, 2013, 1:26:18 AM3/6/13
to golan...@googlegroups.com
> Here is the snippet: http://pastebin.com/gLyHrrP0

Sorry, but do I compile that?

Alex

John Doe

unread,
Mar 6, 2013, 2:30:15 AM3/6/13
to golan...@googlegroups.com
You'll need Microsoft's C++ compiler with all the variables set up.
I'm linking You the VS2012 project (The executable is in the /Debug folder).

George McBay

unread,
Mar 6, 2013, 2:49:43 PM3/6/13
to golan...@googlegroups.com


On Monday, March 4, 2013 5:51:38 PM UTC-8, John Doe wrote:
An obscure error is returned by WinApi when invoking the ProtectEncryptData:

"The operation completed successfully."

IIRC this is what you're supposed to see on success.  The Win32 API calls through Proc/Call pull the err value from GetLastError/FormatMessage, which if the call worked as expected will result in the "error" message you see ("The operation completed successfully.").  

You should be looking at the r1, r2 results from the call to Call and analyzing them based on whatever call it is you're making to determine if there is actually any problem you should worry about since all of these API calls use old-school C-style return overloading to signal errors.

I'm not sure if the non-nil err result in this situation is intentional or a bug, it does feel inconsistent with normal Go error handling.



The same error gets returned, when i call WinApi LocalFree on the byte array pointer.
New version:


brainman

unread,
Mar 6, 2013, 8:34:03 PM3/6/13
to golan...@googlegroups.com
John,

Our programs have a bug. This "*p++" does not do what you think it does. Go does not have pointer arithmetic, and I should have picked that up quickly. But, I guess, I have been doing too much C lately :-).

Here http://play.golang.org/p/fknP9AuLU- is working version.

Alex

John Doe

unread,
Mar 7, 2013, 4:31:47 AM3/7/13
to golan...@googlegroups.com
Awesome, thank you again.

Cheers
J.
Reply all
Reply to author
Forward
0 new messages