1
Discussion - Software / how to use FTDI USB-Key
« on: October 27, 2020, 01:10:42 AM »
Hi,
I am using FTDI USB Key as a dongle key. Does anyone know how to use FTDI USB Key? My software is using MFC C++ to program. Been study this usb-key two days, I have successfully generate private key and public key but I stuck at signing dongle key. I have some questions want to ask:
1) The sequence to make this USB-Key work is GenerateKey() -> put_PrivateKey() -> SignDonglePassword() -> VerifyDonglePassword(), correct?
2) When I called SingleDonglePassword() or SignDongle(), I get error message "Insufficient space in EEPROM user data area", does anyone know what it means? And what should I do to solve this issue?
3) Since the private key information and FTDI-ChipID will be store into USB-Key after calling SignDongle(), could I erase this file?
4) After calling SignDongle(), does it mean that this public key will only work corresponding to this FTDI USB Key?
Actually, I get "Exception Occurred" when using below code, if I used Microsoft Visual C++ example code, I will get "Insufficient space in EEPROM user data area" this error message.
The example code is from below link
https://www.ftdichip.com/Support/SoftwareExamples/SafeGuard-IT.htm
I am using FTDI USB Key as a dongle key. Does anyone know how to use FTDI USB Key? My software is using MFC C++ to program. Been study this usb-key two days, I have successfully generate private key and public key but I stuck at signing dongle key. I have some questions want to ask:
1) The sequence to make this USB-Key work is GenerateKey() -> put_PrivateKey() -> SignDonglePassword() -> VerifyDonglePassword(), correct?
2) When I called SingleDonglePassword() or SignDongle(), I get error message "Insufficient space in EEPROM user data area", does anyone know what it means? And what should I do to solve this issue?
3) Since the private key information and FTDI-ChipID will be store into USB-Key after calling SignDongle(), could I erase this file?
4) After calling SignDongle(), does it mean that this public key will only work corresponding to this FTDI USB Key?
Actually, I get "Exception Occurred" when using below code, if I used Microsoft Visual C++ example code, I will get "Insufficient space in EEPROM user data area" this error message.
The example code is from below link
https://www.ftdichip.com/Support/SoftwareExamples/SafeGuard-IT.htm
Code: [Select]
void CTestDlg::OnBnClickedGenerate()
{
HRESULT hResult;
SAFEARRAY *pPublicKey;
SAFEARRAY *pPrivateKey;
CFile file;
if(!ptrISetupDongle)
return;
hResult = ptrISetupDongle->GenerateKey(&pPublicKey);
if (FAILED(hResult))
{
MessageBox(L"Failed to generate public key!");
return;
}
else
{
if(WriteToKeyFile(pPublicKey, L"public.key"))
MessageBox(L"Success to create public key file!");
}
hResult = ptrISetupDongle->get_PrivateKey(&pPrivateKey);
if (FAILED(hResult))
{
MessageBox(L"Failed to generate private key!");
return;
}
else
{
if(WriteToKeyFile(pPrivateKey, L"private.key"))
MessageBox(L"Success to create private key file!");
}
}
void CTestDlg::OnBnClickedPutPrivatekey()
{
HRESULT hResult;
if(!ptrISetupDongle)
return;
SAFEARRAY *pPrivateKey = ReadKeyFile(L"private.key");
if(!pPrivateKey)
return;
hResult = ptrISetupDongle->put_PrivateKey(pPrivateKey);
if (FAILED(hResult))
{
MessageBox(L"Failed to put private key!");
SafeArrayDestroy(pPrivateKey);
}
else
{
MessageBox(L"Success to put private key!");
SafeArrayDestroy(pPrivateKey);
}
}
void CTestDlg::OnBnClickedSignDongle()
{
HRESULT hResult;
if(!ptrISetupDongle)
return;
hResult = ptrISetupDongle->SignDongle();
if (FAILED(hResult))
{
_com_error err(hResult); // _com_error
LPCTSTR errMsg = err.ErrorMessage();
MessageBox(errMsg);
}
else
{
MessageBox(L"Success to sign dongle key!");
}
}
SAFEARRAY* CTestDlg::ReadKeyFile(CString sFileName)
{
CFile file;
SAFEARRAY *pTheKey = nullptr;
if(file.Open(sFileName, (CFile::modeRead | CFile::typeBinary)))
{
UINT Length = (UINT)file.GetLength();
if(Length)
{
SAFEARRAYBOUND rgsabound;
rgsabound.lLbound = 0;
rgsabound.cElements = Length;
pTheKey = SafeArrayCreate(VT_UI1, 1, &rgsabound);
SafeArrayAccessData(pTheKey,&pTheKey->pvData);
if(pTheKey != NULL)
file.Read(pTheKey->pvData, Length);
}
file.Close();
SafeArrayUnaccessData(pTheKey);
}
return pTheKey;
}
BOOL CTestDlg::WriteToKeyFile(SAFEARRAY* pTheKey, CString sFileName)
{
CFile file;
long lLength;
SafeArrayGetUBound(pTheKey, pTheKey->cDims, &lLength);
SafeArrayAccessData(pTheKey,&pTheKey->pvData);
if (!(file.Open(sFileName, (CFile::modeCreate | CFile::modeWrite | CFile::typeBinary))))
return FALSE;
file.Write(pTheKey->pvData, lLength+1); // 0 based
file.Close();
SafeArrayUnaccessData(pTheKey);
SafeArrayDestroy(pTheKey);
return TRUE;
}