当前位置: 首页>>代码示例>>C++>>正文


C++ deskey函数代码示例

本文整理汇总了C++中deskey函数的典型用法代码示例。如果您正苦于以下问题:C++ deskey函数的具体用法?C++ deskey怎么用?C++ deskey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了deskey函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: dencrypt_3des

int	__stdcall dencrypt_3des(unsigned char* key,long keylen,unsigned char *data,short datalen,unsigned char *Des_result)
{
	unsigned char szkey[9];
	unsigned char szplain[9];
	unsigned char szcipher[9];
	if(keylen != 16)
		return INVALID_KEY_LEN;
	if(datalen != 8)
		return INVALID_DATA_LEN;

	memset(szkey,0,sizeof(szkey));
	memset(szplain,0,sizeof(szplain));
	memset(szcipher,0,sizeof(szcipher));

	memcpy(szkey,key,8);
	memcpy(szcipher,data,8);

	deskey(szkey,1);
	Ddes(szcipher,szplain);

	memcpy(szkey,key+8,8);
	deskey(szkey,0);
	Ddes(szplain,szcipher);

	memcpy(szkey,key,8);
	deskey(szkey,1);
	Ddes(szcipher,szplain);

	memcpy(Des_result,szplain,8);
	return 0;
}
开发者ID:nykma,项目名称:ykt4sungard,代码行数:31,代码来源:desdll.cpp

示例2: vncDecryptPasswdFromFile

char *
vncDecryptPasswdFromFile(char *fname)
{
    FILE *fp;
    int i, ch;
    unsigned char *passwd = (unsigned char *)malloc(9);

    if (strcmp(fname, "-") != 0) {
	if ((fp = fopen(fname,"r")) == NULL)
	    return NULL;
    } else {
	fp = stdin;
    }

    for (i = 0; i < 8; i++) {
	ch = getc(fp);
	if (ch == EOF)
	    break;
	passwd[i] = ch;
    }

    if (fp != stdin)
	fclose(fp);

    if (i != 8)                 /* Could not read eight bytes */
	return NULL;

    deskey(s_fixedkey, DE1);
    des(passwd, passwd);

    passwd[8] = 0;

    return (char *)passwd;
}
开发者ID:gvsurenderreddy,项目名称:AlmostVPNPro,代码行数:34,代码来源:vncauth.c

示例3: vncDecryptPasswdFromFile

char *
vncDecryptPasswdFromFile(char *fname)
{
    FILE *fp;
    int i, ch;
    unsigned char *passwd = (unsigned char *)malloc(9);

    if ((fp = fopen(fname,"r")) == NULL) return NULL;

    for (i = 0; i < 8; i++) {
        ch = getc(fp);
        if (ch == EOF) {
            fclose(fp);
            return NULL;
        }
        passwd[i] = ch;
    }

    fclose(fp);

    deskey(fixedkey, DE1);
    des(passwd, passwd);

    passwd[8] = 0;

    return (char *)passwd;
}
开发者ID:OS2World,项目名称:APP-INTERNET-PMVNC-Client,代码行数:27,代码来源:vncauth.c

示例4: vncEncryptAndStorePasswd

int
vncEncryptAndStorePasswd(char *passwd, char *fname)
{
    FILE *fp;
    int i;
    unsigned char encryptedPasswd[8];

    if ((fp = fopen(fname,"w")) == NULL) return 1;

    chmod(fname, S_IRUSR|S_IWUSR);

    /* pad password with nulls */

    for (i = 0; i < 8; i++) {
        if (i < strlen(passwd)) {
            encryptedPasswd[i] = passwd[i];
        } else {
            encryptedPasswd[i] = 0;
        }
    }

    /* Do encryption in-place - this way we overwrite our copy of the plaintext
       password */

    deskey(fixedkey, EN0);
    des(encryptedPasswd, encryptedPasswd);

    for (i = 0; i < 8; i++) {
        putc(encryptedPasswd[i], fp);
    }

    fclose(fp);
    return 0;
}
开发者ID:OS2World,项目名称:APP-INTERNET-PMVNC-Client,代码行数:34,代码来源:vncauth.c

示例5: main

int main() {
    char *key = "browsers";
    unsigned char data[16];
    int j;
    FILE *in, *out;

    deskey(key, EN0);
    
    in = fopen("challenge", "r");
    if (!in) {
        printf("failed opening challenge\n");
        exit(1);
    }
    fread(data, 1, 16, in);
    fclose(in);

    for (j=0; j<16; j += 8) {
        des(data+j, data+j);
    }

    out = fopen("out", "w+");
    if (!out) {
        printf("failed opening out\n");
        exit(1);
    }
    fwrite(data, 1, 16, out);
    fclose(out);

    return 0;
}
开发者ID:HoTaeWang,项目名称:node-des,代码行数:30,代码来源:main.c

示例6: deskey

int DES::decrypt ( char key[8], char* data, int blocks )
{
   if ((!data)||(blocks<1))
	  return 0;
   deskey ( (unsigned char *)key, DECRYPT );
   des ( (unsigned char *)data, (unsigned char *)data, blocks);
   return 1;
};
开发者ID:nykma,项目名称:ykt4sungard,代码行数:8,代码来源:mydes.cpp

示例7: memcpy

int CHttpDes::des_cbc_pkcs7_decrypt(uchar* from, int nLength,  uchar * to, uchar key[], uchar iv[])
{
	if(nLength % 8)
	{
		return 0;		//数据不正确
	}

	//XOR
	uchar preEnc[8],buffer[8];
	memcpy(preEnc,iv,8);

	deskey(key,DE1);

	int i = 0;
	for(; i<nLength; i+=8)
	{
		uchar* ps = from + i;
		uchar* pd = to + i;

		des(ps,buffer);

		//XOR
		for(int j = 0; j < 8; ++j)
		{
			buffer[j] ^= preEnc[j];
		}

		if(nLength - i > 8)
		{
			//保存前一个输出
			memcpy(preEnc, ps,8);
			memcpy(pd,buffer,sizeof(buffer));
		}
		else
		{
			//去除数据尾
			uchar chEnd = buffer[sizeof(buffer) - 1];
			if(chEnd > 0 && chEnd < 9)
			{
				//有可能是填充字符,去除掉
				for(int j = sizeof(buffer) - 1; j >= (int)(sizeof(buffer) - chEnd); --j)
				{
					if(buffer[j] != chEnd)
						return 0;
				}
				int nSize =nLength - chEnd;
				memcpy(pd, buffer, sizeof(buffer) - chEnd);
				return nLength - chEnd;
			}
			else
			{
				//数据格式不正确
				return 0;
			}
		}
	}
	return 0;
}
开发者ID:huos3203,项目名称:SISpeciesNotes,代码行数:58,代码来源:HttpDes.cpp

示例8: rfb_crypt

void rfb_crypt(CARD8 *dst_buf, CARD8 *src_buf, unsigned char *password)
{
  unsigned char key[8];

  memset(key, 0, 8);
  strncpy((char *)key, (char *)password, 8);
  deskey(key, EN0);
  des(src_buf, dst_buf);
  des(src_buf + 8, dst_buf + 8);
}
开发者ID:hanzhaogang,项目名称:chromium-1,代码行数:10,代码来源:rfblib.c

示例9: dencrypt_des

int	__stdcall dencrypt_des(unsigned char* key,long keylen,unsigned char *data,short datalen,unsigned char *Des_result)
{
	if(keylen != 8)
		return INVALID_KEY_LEN;
	if(datalen != 8)
		return INVALID_DATA_LEN;
	deskey(key,1);
	Ddes(data,Des_result);
	return 0;
}
开发者ID:nykma,项目名称:ykt4sungard,代码行数:10,代码来源:desdll.cpp

示例10: dynatab_freeze_encrypted

/*-------------------------------------------------------------------------
  Write the dynatab to the given file in a format encrypted with key,
  suitable for restoration with dynatab_thaw_encrypted.
-------------------------------------------------------------------------*/
void dynatab_freeze_encrypted(dynatab_t *tab, FILE *fp, const unsigned char key[8])
{
	dynatab_encrypted_freeze_t d;
	size_t encrypted_unit;
	int nwritten;
	int n;
	size_t chunk;
	char buf[crypttab_RW_BUFFER_SIZE];
	char *pbuf;
	char unitbuf[crypttab_RW_BUFFER_SIZE];
	
	d.magic = dynatab_encrypted_MAGIC;
	d.n_used = tab->n_used;
	d.unit = tab->unit;
	/* round up to nearest multiple of 8 */
	encrypted_unit = d.unit + 7 - (d.unit + 7) % 8;

	assert(encrypted_unit <= crypttab_RW_BUFFER_SIZE);
	assert(d.n_used <= 5000);
	DPRINT(("dynatab_freeze_encrypted: Saving %d elements of size %d (%d encrypted).\n", d.n_used, tab->unit, encrypted_unit));

	nwritten = fwrite(&d, sizeof(d), 1, fp);
	if (nwritten != 1) {
		DPRINT(("dynatab_freeze_encrypted: Error writing info.\n"));
		return;
	}
	
	pbuf = buf;
	memset(unitbuf, 0, encrypted_unit);
	deskey(key, EN0);
	for (n = 0; n < tab->n_used; n++) {
		if (pbuf - buf + encrypted_unit > crypttab_RW_BUFFER_SIZE) {
			/* if the write buffer is full, write it to disk, then start
			 * adding at the beginning of the buffer again
			 */
			nwritten = fwrite(buf, (pbuf - buf), 1, fp);
			if (nwritten != 1) {
				DPRINT(("dynatab_freeze_encrypted: Error writing unit %d (wrote %d x %d).\n", n, (pbuf - buf), nwritten));
				return;  /* need an error code? */
			}
			pbuf = buf;
		}
		/* encrypt the entry and add it to the write buffer in 8 byte chunks */
		memcpy(unitbuf, (char *)tab->buf + n * tab->unit, tab->unit);
		for (chunk = 0; chunk < encrypted_unit; chunk += 8, pbuf += 8)
			des(unitbuf + chunk, pbuf);
	}
	
	/* Write the last partial buffer to disk */
	nwritten = fwrite(buf, (pbuf - buf), 1, fp);
	if (nwritten != 1) {
		DPRINT(("dynatab_freeze_encrypted: Error writing unit %d.\n", n));
		return;  /* need an error code? */
	}
}
开发者ID:BygoneWorlds,项目名称:anet,代码行数:59,代码来源:crypttab.c

示例11: desired

/*!
 Initialize the LTC_DES block cipher
 @param key The symmetric key you wish to pass
 @param keylen The key length in bytes
 @param num_rounds The number of rounds desired (0 for default)
 @param skey The key in as scheduled by this function.
 @return CRYPT_OK if successful
 */
static int ltc_des_setup(const unsigned char *key, unsigned long keylen, int num_rounds,
                        ccecb_ctx *skey)
{
    ltc_des_keysched *des;

    des = (ltc_des_keysched *)skey;

    if (num_rounds != 0 && num_rounds != 16) {
        return -1; /* CRYPT_INVALID_ROUNDS; */
    }

     if (keylen != 8) {
        return -1; /* CRYPT_INVALID_KEYSIZE; */
    }

    deskey(key, EN0, des->ek);
    deskey(key, DE1, des->dk);

    return 0; /* CRYPT_OK; */
}
开发者ID:randombit,项目名称:hacrypto,代码行数:28,代码来源:ccdes_ltc_common.c

示例12: vncDecryptPasswd

/*
 *   Decrypt a password.  Returns a pointer to a newly allocated
 *   string containing the password or a null pointer if the password could
 *   not be retrieved for some reason.
 */
char *
vncDecryptPasswd(unsigned char *inouttext)
{
    unsigned char *passwd = (unsigned char *)malloc(9);

    deskey(fixedkey, DE1);
    des(inouttext, passwd);

    passwd[8] = 0;

    return (char *)passwd;
}
开发者ID:daniel-lucio,项目名称:vncrepeater,代码行数:17,代码来源:vncauth.cpp

示例13: desired

/*!
 Initialize the 3LTC_DES-EDE block cipher
 @param key The symmetric key you wish to pass
 @param keylen The key length in bytes
 @param num_rounds The number of rounds desired (0 for default)
 @param skey The key in as scheduled by this function.
 @return CRYPT_OK if successful
 */
static int ltc_des3_setup(const unsigned char *key, unsigned long keylen, int num_rounds,
                        ccecb_ctx * skey)
{
    ltc_des3_keysched *des3;

    des3 = (ltc_des3_keysched *)skey;

    if(num_rounds != 0 && num_rounds != 16) {
        return -1; /* CRYPT_INVALID_ROUNDS; */
    }

    if (keylen != 24) {
        return -1; /* CRYPT_INVALID_KEYSIZE; */
    }

    deskey(key,    EN0, des3->ek[0]);
    deskey(key+8,  DE1, des3->ek[1]);
    deskey(key+16, EN0, des3->ek[2]);

    deskey(key,    DE1, des3->dk[2]);
    deskey(key+8,  EN0, des3->dk[1]);
    deskey(key+16, DE1, des3->dk[0]);

    return 0; /* CRYPT_OK; */
}
开发者ID:randombit,项目名称:hacrypto,代码行数:33,代码来源:ccdes3_ltc_common.c

示例14: cpu_calc_descrypt1

int cpu_calc_descrypt1(u_char *factor, u_char *key, u_char key_id, size_t key_len)
{
	/* DBG("using cpu descrypt.\n"); */

	u_char keybuf[16] = {0};
	u_char factorbuf[16] = {0};

	switch(key_id)
	{
		case 0x0D:
			/* DBG("Gen key, id: 0x0D\n"); */

			memcpy(keybuf, get_netpara()->CardKey, 8);
			memcpy(factorbuf, factor, 8);

			deskey(keybuf, EN0);
			OneDes(factorbuf);
			deskey(factorbuf, EN0);
			OneDes(key);

			return 0;

		case 0x0E:
			/* DBG("Gen key, id: 0x0E\n"); */

			memcpy(keybuf, get_netpara()->CardKey, 12);
			memcpy(factorbuf, factor, 16);
			*((u_int *)(&factorbuf[8])) = ~(*((u_int *)(&factorbuf[0])));
			*((u_int *)(&factorbuf[12])) = ~(*((u_int *)(&factorbuf[4])));

			stntripdes(factorbuf,keybuf);     	/* 分散因子前8字节,密钥 */
			stntripdes(&factorbuf[8],keybuf); 	/* 分散因子后8字节,密钥 */
			stntripdes(key,factorbuf); 			/* 随机数,XdataKeyBuf中是过程密钥 */

			return 0;

		default:
			return -1;
	}
}
开发者ID:FrankSong28,项目名称:carpos-cl1306,代码行数:40,代码来源:pos_psam.c

示例15: memset

int DES::yencrypt ( char key[8], char* data, int size )
{
   if ((!data)||(size<1))
      return 0;

   // The last char of data is bitwise complemented and filled the rest
   // buffer.If size is 16, it will extend to 24,and 17 still 24.
   char lastChar = *(data+size-1);
   int  blocks = size/8+1;
   memset (data+size, ~lastChar, blocks*8-size);
   deskey ( (unsigned char *)key, ENCRYPT );
   return encrypt ( data, data, blocks);
};
开发者ID:nykma,项目名称:ykt4sungard,代码行数:13,代码来源:mydes.cpp


注:本文中的deskey函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。