|
hi,
i can't run this program why
there is 1 error what is it?
#include "stdafx.h"
#include <dsa.h>
using CryptoPP::DSA;
using CryptoPP::DSA_DER;
using CryptoPP::DSA_P1363;
#include <pubkey.h>
using CryptoPP::PrivateKey;
using CryptoPP::PublicKey;
#include <osrng.h>
using CryptoPP::AutoSeededRandomPool;
#include <files.h>
using CryptoPP::FileSource;
using CryptoPP::FileSink;
using CryptoPP::StringSource;
using CryptoPP::StringSink;
bool CreateDSAKeys();
bool SignDSAMessage();
bool VerifyDSAMessage();
int main(int argc, char* argv[])
{
CreateDSAKeys();
SignDSAMessage();
VerifyDSAMessage();
return 0;
}
bool CreateDSAKeys()
{
AutoSeededRandomPool prng;
try
{
// Crypto++ Key Generation
DSA::Signer signer;
PrivateKey& privateKey = signer.AccessPrivateKey();
privateKey.GenerateRandom( prng );
DSA::Verifier verifier( signer );
PublicKey& publicKey = verifier.AccessPublicKey();
// Crypto++ Save Keys
privateKey.Save(FileSink("private.dsa.cpp.key"));
publicKey.Save(FileSink("public.dsa.cpp.key"));
}
catch( CryptoPP::Exception& ex )
{
cerr << "Caught Error:" << endl;
cerr << " " << ex.what() << endl;
return false;
}
catch( std::exception& ex )
{
cerr << "Caught Error:" << endl;
cerr << " " << ex.what() << endl;
return false;
}
return true;
}
bool VerifyDSAMessage()
{
try
{
//
// Crypto++ Load the Pubic Key
//
DSA::Verifier verifier;
PublicKey& publicKey = verifier.AccessPublicKey();
// publicKey.Load(FileSource("public.dsa.cpp.key", true));
// publicKey.Load(FileSource("public.dsa.java.key", true));
publicKey.Load(FileSource("public.dsa.cs.key", true));
//
// Retrieve the Message and the Signature on Message
//
string message, signature;
// C++
FileSource( "dsa.cpp.msg", true, new StringSink( message ) );
FileSource( "dsa.cpp.sig", true, new StringSink( signature ) );
// Java
// FileSource( "dsa.java.msg", true, new StringSink( message ) );
// FileSource( "dsa.java.sig", true, new StringSink( signature ) );
// C#
// FileSource( "dsa.cs.msg", true, new StringSink( message ) );
// FileSource( "dsa.cs.sig", true, new StringSink( signature ) );
//*
// --- Begin Java Specific Conversion ---
//
// Convert: DER -> P1363
//
// Java is DER Encoded Sequence.
// Crypto++ is P1363 format.
/*
{
// From dsa.h: If toFormat == DSA_P1363,
// bufferSize must equal publicKey.SignatureLength()
size_t length = verifier.SignatureLength();
// A buffer for the conversion
byte* buffer = new byte[ length ];
// Sh*t or Go Blind. You make the choice.
if( !buffer ) { return false; }
// Reuse length
length = CryptoPP::DSAConvertSignatureFormat(
buffer, length, DSA_P1363, (const byte*)signature.c_str(),
signature.length(), DSA_DER );
// Reinitialize signature so that it can be used
// in the verifier below with minimal effort
signature = string( (const char*)buffer, length );
delete[] buffer;
}
*/
// --- End Java Specific Conversion ---
//*/
//
// Verify the Signature on the Message
//
bool result = verifier.VerifyMessage(
(const byte*)message.c_str(), message.length(),
(const byte*)signature.c_str(), signature.length() );
if( result )
{
cout << "Signature on Message verified" << endl;
}
else
{
cerr << "Signature on Message not verified" << endl;
return false;
}
//
// Convert the Message
//
int nChars = MultiByteToWideChar( CP_UTF8, 0,
message.c_str(), -1, NULL, NULL );
wchar_t* p = new wchar_t[ nChars ];
if( !p ) { return false; }
MultiByteToWideChar( CP_UTF8, 0, message.c_str(), -1, p, nChars );
wstring wide( p );
delete[] p;
}
catch( CryptoPP::Exception& ex )
{
cerr << "Caught Error:" << endl;
cerr << " " << ex.what() << endl;
return false;
}
catch( std::exception& ex )
{
cerr << "Caught Error:" << endl;
cerr << " " << ex.what() << endl;
return false;
}
return true;
}
bool SignDSAMessage()
{
try
{
//
// Crypto++ Load Private Key
//
DSA::Signer signer;
PrivateKey& privateKey = signer.AccessPrivateKey();
privateKey.Load(FileSource("private.dsa.cpp.key", true));
// Convert the Message
wstring wide = L"Crypto Interop: \u9aa8";
int nChars = WideCharToMultiByte( CP_UTF8, 0,
wide.c_str(), -1, NULL, 0, NULL, FALSE );
char* p = new char[ nChars ];
if( !p ) { return false; }
nChars = WideCharToMultiByte( CP_UTF8, 0,
wide.c_str(), -1, p, nChars, NULL, FALSE );
string narrow( p );
delete[] p;
//
// Sign the Message
//
// Set up for SignMessage()
byte* s = new byte[ signer.MaxSignatureLength() ];
if( !s ) { return false; }
// Sign...
AutoSeededRandomPool prng;
size_t length = signer.SignMessage( prng,
(const byte*) narrow.c_str(), narrow.length(), s );
// Convenience
string signature( (const char*)s, length );
// --- Begin Java Specific Conversion ---
//
// Convert: P1363 -> DER
//
// Crypto++ uses P1363 format.
// Java requires a DER encoded sequence.
/*
{
// Determine size of required buffer
// We can call with a null buffer and 0 size
// when going in this direction
length = CryptoPP::DSAConvertSignatureFormat(
NULL, 0, DSA_DER, (const byte*)signature.c_str(),
signature.length(), DSA_P1363 );
// A buffer for the conversion
byte* buffer = new byte[ length ];
// Sh*t or Go Blind. You make the choice.
if( !buffer ) { return false; }
// Reuse length
length = CryptoPP::DSAConvertSignatureFormat(
buffer, length, DSA_DER, (const byte*)signature.c_str(),
signature.length(), DSA_P1363 );
// Reinitialize signature so that it can be used
// in the verifier below with minimal effort
signature = string( (const char*)buffer, length );
delete[] buffer;
}
*/
// --- End Java Specific Conversion ---
//
// Save the Message and the Signature on Message
//
// mofs: message filestream
// sofs: signature filestream
ofstream mofs, sofs;
mofs.open("dsa.cpp.msg", ios_base::binary | ios_base::trunc );
sofs.open("dsa.cpp.sig", ios_base::binary | ios_base::trunc );
// Save Original Message
mofs.write( narrow.c_str(), (int)narrow.length() );
// Save Signature on Message
sofs.write( (const char*)signature.c_str(), (int)length );
// Cleanup
sofs.close();
mofs.close();
}
catch( CryptoPP::Exception& ex )
{
cerr << "Caught Error:" << endl;
cerr << " " << ex.what() << endl;
return false;
}
catch( std::exception& ex )
{
cerr << "Caught Error:" << endl;
cerr << " " << ex.what() << endl;
return false;
}
return true;
}
|
|
|
|
|
sarroya wrote: there is 1 error what is it?
1/ Read the sticky posting about how to post a good question... And to use an actual subject line.
2/ This isn't a quiz area. If you want to know what's wrong, try and compile it yourself and look at the messages.
After you've fixed it, try single stepping through to see if it behaves as you expect.
3/ I wish you luck when you can narrow down your problem and edit your question.
Best of success,
Iain.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
Hi,
I did following, but I got an error.
pPopupMenu = new CMenu();
if( pPopupMenu->CreatePopupMenu())
{
pPopupMenu->LoadMenu(MAKEINTRESOURCE(MENUID); --------------> ERROR
}
I can not use "LoadMenu" for popupmenu? How can I fix?
Best regards,
|
|
|
|
|
I thought you can use it, too [*] - but you will need to add an extra ")" to close the function.
Iain.
[*] can't look and be 100% sure.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
Sorry, that is my typo here.
The program stops at:
BOOL CMenu::Attach(HMENU hMenu)
POPUP MENU
BEGIN
POPUP ""
BEGIN
MENUITEM "Edit", ID_EDIT
MENUITEM "Object ...", ID_OBJECT
MENUITEM SEPARATOR
MENUITEM "Text...", ID_TEXT
END
END
"hMenu" is NULL. Why "hMenu" is null, I created the menu.
Thanks,
|
|
|
|
|
transoft wrote: I can not use "LoadMenu" for popupmenu? How can I fix?
CreatePopupMenu has already attached an HMENU handle to your CMenu object. You cannot attach a second menu like this. You can use CreatePopupMenu or LoadMenu but not both of them on the same CMenu object.
I also recommend avoiding the new/delete and just create the object on the stack. There is no reason to thrash the heap.
Something like this:
CMenu pPopupMenu;
if(pPopupMenu.LoadMenu(MAKEINTRESOURCE(YOUR_RESOURCE_ID)))
{
POINT pt;
GetCursorPos(&pt);
HMENU hmenuTrackPopup = GetSubMenu(pPopupMenu.m_hMenu, 0);
TrackPopupMenu(hmenuTrackPopup, TPM_LEFTALIGN | TPM_LEFTBUTTON, pt.x, pt.y, 0,m_hWnd, NULL);
}
Some MSDN documentation:
Using Menus[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Hi David
Thank you so much.
I have another question for you. I need to create the menubar and toolbar dynamically.
The Mainframe load the default menu from resource like:
"File Window Help"
I want to insert some menu between "File" and "Windows". Could you give some hints?
Best regards,
|
|
|
|
|
The index is a zero based array, you would insert a new menu item as follows:
CMenu m;
if(m.LoadMenu(MAKEINTRESOURCE(YOUR_RESOURCE_ID)))
{
CMenu *pMenu = GetMenu();
if(NULL != pMenu)
{
MENUITEMINFO mii = {0};
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_ID | MIIM_STRING;
mii.dwTypeData = _T("Inserted Menu");
mii.wID = YOUR_RESOURCE_ITEM_ID;
pMenu->InsertMenuItem(1,&mii,TRUE);
}
}
MENUITEMINFO Structure[^]
InsertMenuItem Function[^]
Best Wishes,
-David Delaune
modified on Sunday, July 19, 2009 7:06 PM
|
|
|
|
|
How do you stop a popup menu from closing when clicking with mouse button?
What I want to do is to create a CMFCDropDownListBox with check boxes (to create a drop list with check boxes). I've created a derived class of CMFCDropDownListBox and CMFCRibbonComboBox.
CMFCDropDownListBox inherits from CMFCPopupMenu.
I've tried to add PreTranslateMessage to my derived DropDownListBox class, but LBUTTONUP/DOWN messages never happens.
Any tip on how to do this? A CMFCRibbonComboBox with check boxes..
|
|
|
|
|
I'm not sure exactly what you're after, but if you look at article: Generic Picker Dropdown Control[^], I imitate a combobox.
You could override the OnKillFocus handler (or remove it), and you'd get a menu-a-like window that doesn't get dismissed.
Or you could go straight with my base CGenericPicker class, and derived your own special drop down.
Good luck,
Iain.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
What I'm after it to stop CMFCPopupMenu from getting left button click messages, and handle those messages myself.
|
|
|
|
|
I found out how to do it:
Inherit CMFCPopupMenuBar and handle the button clicks there. In my inherited CMFCDropDownListBox I override GetMenuBar and returns an instance of my inherited CMFCPopupMenuBar class.
|
|
|
|
|
Glad you've solved your own problem - always the best learning experience that way!
Iain.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
Hi, in my application I set the parent of a button to a static control. After I set the owner (setowner) to the parent of the static (the main window) in order to process messages sent when clicking on the button. The problem is that the function OnButtonClicked() is never called when I click on the button.
I did the same thing with a list control, but it works with it.
I don't know how to fix this bug. Any Idea?
Thanks
|
|
|
|
|
I would suggest making a button a child of a static is a bug in itself, but...
Try using spy++ and seeing where the WM_LBUTTONDOWN / BN_CLICKED message(s) get routed. If they disappear into the static control, try adding the SS_NOTIFY style.
Good luck,
Iain.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
Hi, in fact it's due to the splitter class I'm using. CSSplitter which isn't derived from CSplitterWnd but made thanks to a static control. Then I added my button to that control and I had to set the parent to the splitter control. I hadn't really the choice.
I succeeded in solving the bug by adding a message event in MESSAGE_MAP of the class. Then I call SendMessage to call the corresponding function with the parent.
Thanks for your help,
|
|
|
|
|
That sounds like a perfectly good solution to me!
I can understand wanting to let windows do the heavy lifting, but if it does it "wrong"...
Iain.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
Where do I find a full reference (and possible Tutorial) on the Writing of an Installation Script, acceptable to Windows Installer.
Bram van Kampen
|
|
|
|
|
|
Functions exist, MoveTo(x,y) or LineTo(x,y) to draw or move to coordinate points in MFC. Are there also functions to MoveTo or LineTo in 3D? I.E. MoveTo(x,y,z) or LineTo(x,y,z)? Please let me know.
Sid
|
|
|
|
|
Nope, you've to use a 3D library, like, for instance OpenGL or Direct3D .
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
I found a macro "MAKEINTRESOURCE" to convert resource id to resource name. Is there any way to convert resource name to resource id?
Thanks,
|
|
|
|
|
transoft wrote: MAKEINTRESOURCE
Doesn't really convert anything...IIRC, Windows treats any resource name (i.e. character pointer) with a zero high-order word as an integer rather than a string. That's all.
Basically, a resource can be specified with a name OR an integer id. The only difference (as I said) is whether the high-order word is zero or not.
So conversion of resource name to id is completely meaningless, really.
I suppose something like the code below is the closest you could get
int IsResourceNameInt(LPCTSTR resourceName)
{
return ((int)resourceName&0xffff) == ((int)resourceName)?(int)resourceName:-1;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hello,
In my application I have buttons over a static control used to display a background image. The problem is when the window needs to be resized, the controls are not drawn simultaneously, so the controls are flickering. For instance the background image is drawn, and only after controls and it's quite annoying, resulting in a sort of flashing app when resizing.
I tried to use SetRedraw(0) and SetRedraw at the beggining and the end of the function but it doesn't work either.
LockWindowUpdate doesn't work too.
Have you got any solution for that ?
Thanks in advance.
|
|
|
|
|
Did you try "CMemDC" class?
|
|
|
|
|