Merhaba Arkadaslar,
Türkcem biraz kitdir, kusurabakmayin.
Benim Projem de, bir Smartcardlan bir file li Signature edmeliyim.
Peter Guttman'in Cryptlib len calisiyorum.
Bu liblen calisan oldugsa bana insallah yardim edebillir.
Hata [CODE]cryptgetPrivatekey[/CODE] 4. parameter ne oldugunu tam anlamadim
Source Codum su
[CODE]#include <iostream>
#include "cryptlib.h"
#include <string>
using namespace std;
CRYPT_DEVICE cryptDevice;
CRYPT_USER cryptUser;
CRYPT_CONTEXT cryptContext, hashContext, signContext;
CRYPT_ALGO_TYPE cryptAlgo;
CRYPT_KEYSET keyset;
#define SIGNLENGTH 8192
#define SKeyslength 5
int main()
{
char text[100] = "TEXT...TEXT...";
int code = 0;
char signature[SIGNLENGTH];
int signatureLength;
/* Initialise cryptlib */
code = cryptInit();
cout<<"InitBegin : "<<code<<endl;
CRYPT_OPTION_DEVICE_PKCS11_DVR01;
code = cryptSetAttributeString( CRYPT_UNUSED,CRYPT_OPTION_DEVICE_PKCS11_DVR01,"pkcs201n.dll", 12 );
cout<<"SetAttributeString : "<< code<<endl;
code = cryptSetAttribute( CRYPT_UNUSED, CRYPT_OPTION_CONFIGCHANGED, FALSE );
cout<<"SetAttribute : "<< code<<endl;
code = cryptDeviceOpen( &cryptDevice, CRYPT_UNUSED, CRYPT_DEVICE_PKCS11, "[Autodetect]" );
cout<<"DeviceOpen : "<< code<<endl;
/*LOGIN*/
code = cryptSetAttributeString( cryptDevice, CRYPT_DEVINFO_AUTHENT_USER, "1234",4);
if (code == 0)
{
cout<<endl<<"<<LOGIN Erfolgreich>> "<<endl<<endl;
}
else
cout<<endl<<"<<LOGIN Fehlgeschlagen>> (Fehlercode:"<<code<<")"<<endl<<endl;
//SignContext
code = cryptGetPrivateKey(cryptDevice, &signContext, CRYPT_KEYID_NAME, " ", NULL); //4Parameter ???
cout<<"GetPrivateKey : "<< code<<endl;
// Create a hash context
code = cryptCreateContext( &hashContext,CRYPT_UNUSED, CRYPT_ALGO_MD5 );
cout<<"CreateHashContext: "<< code<<endl;
code = cryptEncrypt( hashContext, text, strlen(text));
cout<<"cryptEncrypt: "<< code<<endl;
//Signatur Erstellen
code = cryptCreateSignatureEx(signature, SIGNLENGTH, &signatureLength,
CRYPT_FORMAT_PKCS7 ,signContext, hashContext, CRYPT_UNUSED);
cout<<endl<<"<<CreateSignature>>: "<< code<<endl;
/*Destroy - Close*/
code = cryptDestroyContext (hashContext );
cout<<"DestroyHashContext: "<< code<<endl;
code = cryptDestroyContext( signContext );
cout<<"DestroyDeviceContext: "<< code<<endl;
code = cryptDeviceClose( cryptDevice );
cout<<endl<<endl<<"DeviceClose: "<< code<<endl;
/* Shut down cryptlib */
code = cryptEnd();
cout<<"InitEnd : "<< code<<endl;
return 0;
}
[/CODE]
Sagol yardimlariniz icin