So I am creating for my community a small program that can get my users Mac Address and give to me. after I have the Mac adress I want to encrypt it and give me a code that is simply to find the original not for example like md5. So I want to use it to authenticate my users, but I dont want to reveal this to them because after they will change their MacAdress and it will be the same problem. So a user is trying to connect at my site, I get his Mac adress I encrypt this and send it at my user. My user put this code tu be authenticated wheni receive this code I decrypt it and if the decrypted code is the same with the mac adress that I got from him he can enter
Now i dont know how to put togather this three tapes so for taking the MAc Adress I am using this code:
Code:
static void GetMACaddress(void)
{
IP_ADAPTER_INFO AdapterInfo[16];
DWORD dwBufLen = sizeof(AdapterInfo);
DWORD dwStatus = GetAdaptersInfo(
AdapterInfo,
&dwBufLen);
assert(dwStatus == ERROR_SUCCESS);
PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;
do {
PrintMACaddress(pAdapterInfo->Address);
pAdapterInfo = pAdapterInfo->Next;
}
while(pAdapterInfo);
}
After i took the MAc I encrypt it at a .7pm
Code:
#include <CkCrypt2.h>
#include <CkCert.h>
void ChilkatSample(void)
{
CkCrypt2 crypt;
// Any string argument automatically begins the 30-day trial.
bool success;
success = crypt.UnlockComponent("30-day trial");
if (success != true) {
printf("Crypt component unlock failed\n");
return;
}
// Use public-key encryption with a digital certificate:
crypt.put_CryptAlgorithm("pki");
// There are many ways to select and load a digital certificate.
// Certs can be retrieved from the Windows registry-based
// certificate stores, from database tables, files, etc.
// This example will load a .cer file.
CkCert cert;
success = cert.LoadFromFile("myCert.cer");
if (success != true) {
printf("%s\n",cert.lastErrorText());
return;
}
crypt.SetEncryptCert(cert);
// The CkEncryptFile can encrypt files of any size. The
// encryption occurs in streaming mode, so it is not necessary
// to hold the entire contents of the file in memory at once.
success = crypt.CkEncryptFile("dude.gif","dude.p7m");
if (success != true) {
printf("%s\n",crypt.lastErrorText());
return;
}
success = crypt.CkDecryptFile("dude.p7m","dudeOut.gif");
if (success != true) {
printf("%s\n",crypt.lastErrorText());
return;
}
}
this give me the encrypted code that i send at my user the user return it to me and I decrypt it
Code:
#include <CkCrypt2.h>
#include <CkCreateCS.h>
#include <CkCertStore.h>
#include <CkCert.h>
void ChilkatSample(void)
{
CkCrypt2 crypt;
// Any string argument automatically begins the 30-day trial.
bool success;
success = crypt.UnlockComponent("30-day trial");
if (success != true) {
printf("Crypt component unlock failed\n");
return;
}
// Find our digital certificate from the Current User certificate store.
CkCreateCS ccs;
CkCertStore *certStore = 0;
certStore = ccs.OpenCurrentUserStore();
CkCert *cert = 0;
cert = certStore->FindCertBySubjectCN("Chilkat Software, Inc.");
if (cert == 0 ) {
printf("%s\n",cert->lastErrorText());
delete certStore;
return;
}
delete certStore;
// Verify and restore the original file:
crypt.SetVerifyCert(*cert);
success = crypt.VerifyP7S("license.p7s","license2.rtf");
if (success == false) {
printf("%s\n",crypt.lastErrorText());
delete cert;
return;
}
delete cert;
printf("Success!\n");
}
the code for encrypting and decrypt i found around the web maybe they doesn't work so can anybody tell me another way to encrypt and decrypt the mac adress so the first step is to get th mac adress and encrypt it: i know how to get it but not to encrypt step 2 how to decrypt and verify it with the original code ifa are the same
thank you very much