예제 #1
0
파일: cgi_cookie.c 프로젝트: hyypucs/NTWOAD
int StartCookieMan(void)
{
	char *p, *q;
	int nLen;

	p = getenv("HTTP_COOKIE");
	if (p == NULL) return 1;

	if (strncmp(p, "Cookie: ", 8) == 0) {
		p += 8;
	}

	while (1) {
		if (gnCookieMan >= MAX_COOKIEMAN) break;
		gCookieMan[gnCookieMan] = (COOKIE_FORMAT *)malloc(sizeof(COOKIE_FORMAT));
		if (gCookieMan[gnCookieMan] == NULL) break;

		while (*p == ' ' || *p == '\t')  p++;
		q = strchr(p, '=');
		if (q == NULL) break;
		nLen = q - p;
		gCookieMan[gnCookieMan]->lpszName = (char *)malloc(nLen+1);
		if (gCookieMan[gnCookieMan]->lpszName == NULL) {
			break;
		}
		strncpy(gCookieMan[gnCookieMan]->lpszName, p, nLen);
		*(gCookieMan[gnCookieMan]->lpszName + nLen) = '\0';

		p = q+1;

		q = strchr(p, ';');
		if (q) {
			nLen = q - p;
		}
		else {
			nLen = strlen(p);
		}

		gCookieMan[gnCookieMan]->lpszValue = (unsigned char *)malloc(nLen+1);
		if (gCookieMan[gnCookieMan]->lpszValue == NULL) {
			break;
		}
		strncpy((char *)(gCookieMan[gnCookieMan]->lpszValue), p, nLen);
		*(gCookieMan[gnCookieMan]->lpszValue + nLen) = '\0';

		// Decode
		HexStr2CharStr((char *)(gCookieMan[gnCookieMan]->lpszValue), (char *)(gCookieMan[gnCookieMan]->lpszValue));
		gnCookieMan ++;
		if (q) {
			p = q+1;
		}
		else break;
	}

	return 1;
}
예제 #2
0
void StrCrypt(unsigned char *buf1, unsigned long buf1len, unsigned char *buf2, unsigned long buf2len, unsigned char *key, CryptAction action)
{
    CBlowFish *BlowFish = new CBlowFish(key, strlen((char*)key));

    if(action == Encrypt)
    {
        BlowFish->Encrypt(buf1, buf1, buf1len, CBlowFish::ECB);
        CharStr2HexStr(buf1, (char*)buf2, buf1len);
    }

    else if(action == Decrypt)
    {
        HexStr2CharStr((char*)buf1, buf2, buf2len/2);
        BlowFish->Decrypt(buf2, buf2, buf2len, CBlowFish::ECB);
    }

    delete BlowFish;
};