// ClientCDKey::CreateSymmetricKey // Creates a symmetric key from product name used to save/load CD-Key to/from // the registry. Symmetric key is created via a series of CRCs on the product. void ClientCDKey::CreateSymmetricKey(BFSymmetricKey& theSymKeyR) const { WTRACE("ClientCDKey::CreateSymmetricKey"); WDBG_LL("ClientCDKey::CreateSymmetricKey from product=" << mProduct); CRC16 aCRC; RawBuffer aBuf; // CRC the product and use it as 1st 2 bytes of key aCRC.Put(mProduct); unsigned short aCheckSum = aCRC.GetCRC(); WDBG_LL("ClientCDKey::CreateSymmetricKey First CRC=" << aCheckSum); aBuf.assign(reinterpret_cast<unsigned char*>(&aCheckSum), sizeof(aCheckSum)); // CRC each of 1st 3 chars of product and add them to key. for (int i=0; (i < 3) && (i < mProduct.size()); i++) { aCRC.Put(static_cast<unsigned char>(mProduct[i])); aCheckSum = aCRC.GetCRC(); WDBG_LL("ClientCDKey::CreateSymmetricKey Add CRC=" << aCheckSum); aBuf.append(reinterpret_cast<unsigned char*>(&aCheckSum), sizeof(aCheckSum)); } // Create the key WDBG_LL("ClientCDKey::CreateSymmetricKey Buf=" << aBuf); theSymKeyR.Create(aBuf.size(), aBuf.data()); }
bool AuthContext::LoadVerifierKey(const std::string &theFile) { mCheckedVerifierFile = true; FILE *aFile = fopen(theFile.c_str(),"rb"); if(aFile==NULL) return false; unsigned char aBuf[1024]; RawBuffer aKeyBuf; while(!feof(aFile)) { int aNumRead = fread(aBuf,1,1024,aFile); if(aNumRead>0) aKeyBuf.append(aBuf,aNumRead); } fclose(aFile); AutoCrit aCrit(GetVerifierCrit()); return mVerifierKey.SetPublicKey(aKeyBuf.data(),aKeyBuf.length()); }