1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| char fpCode(const char* password, char* key, char code[33], unsigned char length) { unsigned char pwdLen = strlen(password); unsigned char keyLen = strlen(key);
if ((1 > pwdLen) || (1 > keyLen) || (1u > length) || (length > 32u)) { return 0; }
MD5 hashMD5;
char* pHmd5 = hashMD5.hmac_md5(password, pwdLen, key, keyLen); char hmd5[32]; memcpy(hmd5, pHmd5, 32);
char* pKise = "kise"; char* pRule = hashMD5.hmac_md5(hmd5, 32, pKise, 4); char rule[32]; memcpy(rule, pRule, 32);
char* pSnow = "snow"; char* pSource = hashMD5.hmac_md5(hmd5, 32, pSnow, 4); char source[32]; memcpy(source, pSource, 32);
for (unsigned char i = 0; i < 32; i++) { if (isNaN(source[i])) { if (strchr("sunlovesnow1990090127xykab", rule[i]) != NULL) { source[i] = toupper(source[i]); } } }
if (isNaN(source[0]) == 0) { source[0] = 'K'; }
memset(code, 0, 33); memcpy(code, source, sizeof(char) * length);
return 1; }
|