📄 accountinfomanager.cc
字号:
#include "AccountInfoManager.h"#include <unistd.h>#include <stdio.h>//#define _DEBUG_//----------------------------------------------------------//const int CAccountInfoManager::ConfigTextSize=64;CAccountInfoManager::CAccountInfoManager():ConfigTextSize(64){ //Nothing To Do ? :) pHOME = getenv("HOME"); //Set AES Key: 16Byte //strcpy(strKey,"0123456789012345"); strcpy(strKey,"happyhackingkaye"); MyAES.MakeKey(strKey, CRijndael::sm_chain0, 16, 16); }CAccountInfoManager::~ CAccountInfoManager(){ }//--------------------------------------------------------//加密解密还是有问题,才导致保存信息错误............bool CAccountInfoManager::GetAccountInfo(struct AccountInfo *accountinfo){ char Destr[ConfigTextSize+1]; char Enstr[ConfigTextSize+1]; memset(Destr,0,sizeof(Destr)); memset(Enstr,0,sizeof(Enstr)); FILE *fp; chdir(pHOME); if( ( fp = fopen(".kpassport.dat","r") ) == NULL) {#ifdef _DEBUG_ printf("Configure file dose not Exist!!\n");#endif return false; } fgets(Enstr,sizeof(Enstr),fp);#ifdef _DEBUG_ printf("-----------------------------\n:Enstr:%s\n-------------------------\n",Enstr);#endif MyAES.Decrypt(Enstr, Destr,ConfigTextSize , CRijndael::ECB);#ifdef _DEBUG_ printf("-----------------------------\n:After Descrypt:%s\n-------------------------\n",Destr);#endif sscanf(Destr,"%s%s%d%d%d%d%d%d%d", accountinfo->Username,accountinfo->Password,&accountinfo->IsInternational,&accountinfo->RefreshTimeInterval,&accountinfo->ConnectionTimeout,&accountinfo->IsSaveUsername,&accountinfo->IsSavePassword,&accountinfo->IsAutoLogin,&accountinfo->IsMinToTray); //把用户和密码后的多余字符k截去 accountinfo->Username[strlen(accountinfo->Username)-1]='\0'; accountinfo->Password[strlen(accountinfo->Password)-1]='\0'; fclose(fp); return 0;}bool CAccountInfoManager::SaveAccountInfo(struct AccountInfo accountinfo){ //---------------------------------- char Instr[ConfigTextSize+1]; char Enstr[ConfigTextSize+1]; memset(Instr,0,sizeof(Instr)); memset(Enstr,0,sizeof(Enstr)); //--------------------------------------- chdir(pHOME); FILE *fp; if( ( fp = fopen(".kpassport.dat","w") ) == NULL) { #ifdef _DEBUG_ printf("Configure file could not be opend!!\n");#endif return false; } //如果用户名为空时,用sprintf会取得不正确的数据,所以在用户名和密码后加字符'k' sprintf(Instr,"%sk %sk %d %d %d %d %d %d %d ", accountinfo.Username,accountinfo.Password,accountinfo.IsInternational,accountinfo.RefreshTimeInterval,accountinfo.ConnectionTimeout,accountinfo.IsSaveUsername,accountinfo.IsSavePassword,accountinfo.IsAutoLogin,accountinfo.IsMinToTray); //填充空余的byte...补足到ConfigTextSize byte.. if( strlen(Instr) < ConfigTextSize ) { for(int k = strlen(Instr); k < ConfigTextSize; k++) Instr[k] = 'k'; Instr[ConfigTextSize] = '\0'; } //------------------------------------ //encrypte#ifdef _DEBUG_ printf("-----------------------------\n:Instr:%s\n-------------------------\nhello\n",Instr);#endif MyAES.Encrypt(Instr, Enstr, ConfigTextSize, CRijndael::ECB);#ifdef _DEBUG_ printf("-----------------------------\n:Enstr:%s\n-------------------------\nhello\n",Enstr);#endif //------------------------------------ //save fputs(Enstr,fp); fclose(fp); return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -