📄 msvcdemodlg.cpp
字号:
}
}
}
else
{
m_ulCurrentDogHandle=0;
}
m_iDogIndex=0;
m_bCallOpenFirstInLocal = false;
m_strResult.Format("Close dog succeeded!");
UpdateData(FALSE);
}
void CMSVCDEMODlg::OnButtonVerifyPassword()
{
HRESULT hrReturnCode;
UCHAR ucVerifyCount;
UpdateData(TRUE);
if (m_ulCurrentDogHandle == 0)
{
m_strResult.Format("There is no invalid dog handle.\nYou should call OpenDog firstly!");
UpdateData(FALSE);
return;
}
if (m_strPassword.GetLength()<8)
{
m_strResult.Format("The length of password can not be less than 8!");
UpdateData(FALSE);
return ;
}
memset(m_cPassword, 0, 128);
memcpy(m_cPassword, m_strPassword, m_strPassword.GetLength());
//Call RC_VerifyPassword to verify User or Developer password
hrReturnCode = rc_VerifyPassword(m_ulCurrentDogHandle,m_ucPasswordType,m_cPassword,&ucVerifyCount);
if (hrReturnCode == S_OK)
{
if( RC_PASSWORDTYPE_USER == m_ucPasswordType)
{
m_strResult.Format("Verify user password succeeded!");
}
else if(RC_PASSWORDTYPE_DEVELOPER == m_ucPasswordType)
{
m_strResult.Format("Verify developer password succeeded!");
}
}
else
{
if( RC_PASSWORDTYPE_USER == m_ucPasswordType)
{
m_strResult.Format("Verify user password failed!\nThe verify count left is %d \nThe error code is 0X%X",ucVerifyCount,hrReturnCode);
}
else if(RC_PASSWORDTYPE_DEVELOPER == m_ucPasswordType)
{
m_strResult.Format("Verify developer password failed!\nThe verify count left is %d \nThe error code is 0X%X",ucVerifyCount,hrReturnCode);
}
}
UpdateData(FALSE);
}
void CMSVCDEMODlg::OnButtonChangePassword()
{
HRESULT hrReturnCode;
UpdateData(TRUE);
if (m_ulCurrentDogHandle == 0)
{
m_strResult.Format("There is no invalid dog handle.\nYou should call OpenDog firstly!");
UpdateData(FALSE);
return;
}
if (m_strPassword.GetLength()<8)
{
m_strResult.Format("The length of password can not be less than 8!");
UpdateData(FALSE);
return;
}
memset(m_cPassword, 0, 128);
memcpy(m_cPassword, m_strPassword, m_strPassword.GetLength());//Get the password
//Call RC_ChangePassword to Change the password.
hrReturnCode = rc_ChangePassword(m_ulCurrentDogHandle,m_ucPasswordType,m_cPassword);
if (hrReturnCode == S_OK)
{
if( RC_PASSWORDTYPE_USER == m_ucPasswordType)
{
m_strResult.Format("Change user password succeeded!");
}
else if(RC_PASSWORDTYPE_DEVELOPER == m_ucPasswordType)
{
m_strResult.Format("Change developer password succeeded!");
}
}
else
{
if( RC_PASSWORDTYPE_USER == m_ucPasswordType)
{
m_strResult.Format("Change user password failed!\nThe error code is 0X%X",hrReturnCode);
}
else if(RC_PASSWORDTYPE_DEVELOPER == m_ucPasswordType)
{
m_strResult.Format("Change developer password failed!\nThe error code is 0X%X",hrReturnCode);
}
}
UpdateData(FALSE);
}
void CMSVCDEMODlg::OnButtonSetKey()
{
UCHAR ucKey[16]={0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50};//"ABCDEFGHIJKLMNOP"
HRESULT hrReturnCode;
int iCount;
CString strTmp;
UpdateData(TRUE);
if (m_ulCurrentDogHandle == 0)
{
m_strResult.Format("There is no invalid dog handle.\nYou should call OpenDog firstly!");
UpdateData(FALSE);
return;
}
//Call RC_SetKey to set the signature key or AES key.
hrReturnCode = rc_SetKey(m_ulCurrentDogHandle,m_ucKeyType,ucKey,16);
if (hrReturnCode!=S_OK)
{
if(RC_KEY_AES == m_ucKeyType)
{
m_strResult.Format("Set AES Key failed!\nThe error code is 0X%X.",hrReturnCode);
}
else if(RC_KEY_SIGN == m_ucKeyType)
{
m_strResult.Format("Set Sign Key failed!\nThe error code is 0X%X.",hrReturnCode);
}
}
else
{
if(RC_KEY_AES == m_ucKeyType)
{
m_strResult.Format("Set AES Key succeeded!\nThe key is:\n");
}
else if(RC_KEY_SIGN == m_ucKeyType)
{
m_strResult.Format("Set Sign Key succeeded!\nThe key is:\n");
}
for(iCount=0;iCount<16;iCount++)
{
strTmp.Format("0X%02X " ,ucKey[iCount]);
m_strResult = m_strResult+strTmp;
if((iCount+1)%8==0)
{
strTmp.Format("\n");
m_strResult = m_strResult+strTmp;
}
}
}
UpdateData(FALSE);
}
void CMSVCDEMODlg::OnButtonSignData()
{
HRESULT hrReturnCode;
int iCount;
CString strTmp;
UCHAR ucSignData[256];
ULONG ulSignLen=16;
ULONG ulResultLen=16;
UCHAR ucSignResult[16];
UpdateData(TRUE);
if (m_ulCurrentDogHandle == 0)
{
m_strResult.Format("There is no invalid dog handle.\nYou should call OpenDog firstly!");
UpdateData(FALSE);
return;
}
for(iCount=0;iCount<256;iCount++)
{
ucSignData[iCount]=iCount;
}
//Call RC_SignData to get the result of signature
hrReturnCode=rc_SignData(m_ulCurrentDogHandle,ucSignData,ulSignLen,ucSignResult,&ulResultLen);
if (hrReturnCode!=S_OK)
{
m_strResult.Format("Sign data failed!\nThe error code is 0X%X.",hrReturnCode);
}
else
{
m_strResult.Format("Sign data succeeded!\nThe result is:\n");
for(iCount=0;iCount<16;iCount++)
{
strTmp.Format("0X%02X " ,ucSignResult[iCount]);
m_strResult = m_strResult+strTmp;
if((iCount+1)%8==0)
{
strTmp.Format("\n");
m_strResult = m_strResult+strTmp;
}
}
}
UpdateData(FALSE);
}
void CMSVCDEMODlg::OnButtonEncryptData()
{
HRESULT hrReturnCode;
int iCount;
CString strTmp;
UCHAR ucEncryptData[16];
ULONG ulEncryptLen=16;
ULONG ulResultLen=16;
UCHAR ucResult[16];
UpdateData(TRUE);
if (m_ulCurrentDogHandle == 0)
{
m_strResult.Format("There is no invalid dog handle.\nYou should call OpenDog firstly!");
UpdateData(FALSE);
return;
}
for(iCount=0;iCount<16;iCount++)
{
ucEncryptData[iCount]=iCount;
}
//Call RC_EncryptData to get the result of encryption
hrReturnCode=rc_EncryptData(m_ulCurrentDogHandle,ucEncryptData,ulEncryptLen,ucResult,&ulResultLen);
if (hrReturnCode!=S_OK)
{
m_strResult.Format("Encrypt data failed!\nThe error code is 0X%X.",hrReturnCode);
}
else
{
m_strResult.Format("Encrypt data succeeded!\nThe encrypted data is:\n");
for(iCount=0;iCount<16;iCount++)
{
strTmp.Format("0X%02X " ,ucEncryptData[iCount]);
m_strResult = m_strResult+strTmp;
if((iCount+1)%8==0)
{
strTmp.Format("\n");
m_strResult = m_strResult+strTmp;
}
}
strTmp.Format("\nThe result is:\n");
m_strResult = m_strResult+strTmp;
for(iCount=0;iCount<16;iCount++)
{
m_ucEncryptedData[iCount]=ucResult[iCount];//store the encrypted data
strTmp.Format("0X%02X " ,ucResult[iCount]);
m_strResult = m_strResult+strTmp;
if((iCount+1)%8==0)
{
strTmp.Format("\n");
m_strResult = m_strResult+strTmp;
}
}
}
UpdateData(FALSE);
}
void CMSVCDEMODlg::OnButtonConvertData()
{
HRESULT hrReturnCode;
int iCount;
UCHAR ucConvertData[16];
ULONG ulLen=16;
ULONG ulResult;
CString strTmp;
UpdateData(TRUE);
if (m_ulCurrentDogHandle == 0)
{
m_strResult.Format("There is no invalid dog handle.\nYou should call OpenDog firstly!");
UpdateData(FALSE);
return;
}
for(iCount=0;iCount<16;iCount++)
{
ucConvertData[iCount]=0x41+iCount;
}
//Call RC_ConvertData to get the result of convertion
hrReturnCode = rc_ConvertData(m_ulCurrentDogHandle,ucConvertData,ulLen,&ulResult);
if (hrReturnCode!=S_OK)
{
m_strResult.Format("Convert data failed!\nThe error code is 0X%X.",hrReturnCode);
}
else
{
m_strResult.Format("Convert data succeeded!\n\nThe data is:\n");
for(iCount=0;iCount<16;iCount++)
{
strTmp.Format("0X%02X " ,ucConvertData[iCount]);
m_strResult = m_strResult+strTmp;
if((iCount+1)%8==0)
{
strTmp.Format("\n");
m_strResult = m_strResult+strTmp;
}
}
strTmp.Format("\nThe result is: DEC:%u HEX:0X%X",ulResult,ulResult);
m_strResult = m_strResult+strTmp;
}
UpdateData(FALSE);
}
void CMSVCDEMODlg::OnButtonDecryptData()
{
HRESULT hrReturnCode;
int iCount;
CString strTmp;
ULONG ulDecryptLen=16;
ULONG ulResultLen=16;
UCHAR ucResult[16];
UpdateData(TRUE);
if (m_ulCurrentDogHandle == 0)
{
m_strResult.Format("There is no invalid dog handle.\nYou should call OpenDog firstly!");
UpdateData(FALSE);
return;
}
//Call RC_DecryptData to get the result of decryption
hrReturnCode=rc_DecryptData(m_ulCurrentDogHandle,m_ucEncryptedData,ulDecryptLen,ucResult,&ulResultLen);
if (hrReturnCode!=S_OK)
{
m_strResult.Format("Decrypt data failed!\nThe error code is 0X%X.",hrReturnCode);
}
else
{
m_strResult.Format("Decrypt data succeeded!\nThe decrypted data is:\n");
for(iCount=0;iCount<16;iCount++)
{
strTmp.Format("0X%02X " ,m_ucEncryptedData[iCount]);
m_strResult = m_strResult+strTmp;
if((iCount+1)%8==0)
{
strTmp.Format("\n");
m_strResult = m_strResult+strTmp;
}
}
strTmp.Format("\nThe Result is:\n");
m_strResult = m_strResult+strTmp;
for(iCount=0;iCount<16;iCount++)
{
strTmp.Format("0X%02X " ,ucResult[iCount]);
m_strResult = m_strResult+strTmp;
if((iCount+1)%8==0)
{
strTmp.Format("\n");
m_strResult = m_strResult+strTmp;
}
}
}
UpdateData(FALSE);
}
void CMSVCDEMODlg::OnButtonGetRandom()
{
HRESULT hrReturnCode;
int iCount;
UCHAR ucRandomData[256];
UCHAR ucLen=255;
CString strTmp;
UpdateData(TRUE);
if (m_ulCurrentDogHandle == 0)
{
m_strResult.Format("There is no invalid dog handle.\nYou should call OpenDog firstly!");
UpdateData(FALSE);
return;
}
//Call RC_GetRandom to get the random data
hrReturnCode = rc_GetRandom(m_ulCurrentDogHandle,ucRandomData,ucLen);
if (hrReturnCode!=S_OK)
{
m_strResult.Format("Get random data failed!\nThe error code is 0X%X.",hrReturnCode);
}
else
{
m_strResult.Format("Get random data succeeded!\n\nThe random data is\n");
for(iCount=0;iCount<ucLen;iCount++)
{
strTmp.Format("0X%02X " ,ucRandomData[iCount]);
m_strResult = m_strResult+strTmp;
if((iCount+1)%8==0)
{
strTmp.Format("\n");
m_strResult = m_strResult+strTmp;
}
}
}
UpdateData(FALSE);
}
void CMSVCDEMODlg::OnButtonCreateDir()
{
HRESULT hrReturnCode;
USHORT usDirSize = 266;
UpdateData(TRUE);
if (m_ulCurrentDogHandle == 0)
{
m_strResult.Format("There is no invalid Dog handle.\nYou should call OpenDog first!");
UpdateData(FALSE);
return;
}
//Call RC_CreateDir to create directory file
hrReturnCode = rc_CreateDir(m_ulCurrentDogHandle,m_sDirID,usDirSize);
if (S_OK == hrReturnCode)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -