예제 #1
0
void DEC3_Encrypt(unsigned char *in_buf, unsigned char *miwen)
{
	unsigned char buf1[8],buf2[8];

	DES_Encrypt(&DES_key[0],in_buf,buf1);
    DES_Decrypt(&DES_key[8],buf1,buf2);
	DES_Encrypt(&DES_key[0],buf2,miwen);
}
예제 #2
0
int ReadFileProcess(int *ver_len, unsigned char*pfile_buf,  unsigned long *file_len,FILE * fpReadIn )
{

    LogDisplay("读入文件版本\r\n");
    if((*ver_len=ReadVersion(Ver_Buf,Version_File_Name))<0)
      return -1;

    #if 0

    /*文件DES加密后输出*/
    LogDisplay("对升级文件进行加密...\r\n");
    if(DES_Encrypt(FileName,keyStr,DESFileName)<0)
	{
	    sprintf(Print_Buf,"File:\t%s DES Encrypt Failed!\r\n",FileName);
	    LogDisplay(Print_Buf);
	    return -1;
	}
    sprintf(Print_Buf,"File: %s DES EncryptSucceed!\r\n",FileName);
    LogDisplay(Print_Buf);

    /*加密文件读入并加入CRC校验*/
    LogDisplay("加密文件添加CRC校验...\r\n");
    #endif

    LogDisplay("读入升级文件...\r\n");
    memset(pfile_buf,0,FLIE_BUFFER_SIZE);
	/*文件读入并CRC32校验*/
    if( File_Crc32( pfile_buf, file_len,fpReadIn,FileName)<0)
	{
        return -1;
	}
    return 1;
}
예제 #3
0
///////////////////////////////////////////////////////////////////////////////
// functions
///////////////////////////////////////////////////////////////////////////////
AS3_Val doAes(void *data, AS3_Val args)
{
	AS3_Val input = NULL;
    unsigned int in_len;
	char * ar;
	AS3_ArrayValue(args, "AS3ValType, IntType", &input, &in_len);
	ar = (char *)malloc(in_len);
	
	AS3_ByteArray_readBytes((void*)ar, input, in_len);
	
	char * aesData;
	int out_len = 0;
	char * keyStr = "kael";
	
	//use AES to Encrypt the bytes
	aesData = DES_Encrypt(ar, keyStr, in_len, &out_len );

	//make a new as3 byteArray var
	AS3_Val baNS = AS3_String("flash.utils");
	AS3_Val baClass = AS3_NSGetS(baNS, "ByteArray");
	AS3_Val emptyParams = AS3_Array("");
	AS3_Val byteArray2 = AS3_New(baClass, emptyParams);
	
	AS3_ByteArray_writeBytes(byteArray2, aesData, out_len);
	return byteArray2;
}
int main( void )
{
	bool success = true;

	/* Example of how to use Single DES encryption and decryption functions. */
	DES_Encrypt(indata, cipherdata, deskey);
	DES_Decrypt(cipherdata, outdata, decryptkey);

	/* Check if decrypted answer is equal to plaintext. */
	for (uint8_t i = 0; i < DES_BLOCK_LENGTH ; i++ ){
		if (indata[i] != outdata[i]){
			success = false;
			break;
		}
	}

	if (success){
	  	while (true){
		/* If the example ends up here everything is ok. */
             nop();
		}
	}else{
		while (true){
		/* If the example ends up here something is wrong. */
             nop();
		}
	}
}
예제 #5
0
int main()
{	
	clock_t a,b;
	a = clock();
        int key_creat[64];
        key(key_creat);
        char *plain;
        char *cipher;
        char *decrypted_mes;
        char plain_input[256]="";
        char cipher_output[256]="";
        char message[256]="";
        int i = 0;
        printf("please input the content to be encrypted:\n");
        scanf("%s",plain_input);
	DES_Encrypt(plain_input,key_creat,cipher_output);
	b = clock();
	printf("\n加密消耗%d毫秒\n",b-a);
	cipher = cipher_output;
        printf("\nthe encrypted message is:\n");
        for(i=0;i<strlen(cipher);i++){
                printf("0x%08x ",cipher_output[i]);
        }
//	system("pause");
	a = clock();
	DES_Decrypt(cipher_output,key_creat,message);
	b = clock();
	printf("\n解密消耗%d毫秒\n",b-a);
        decrypted_mes=message;
        printf("\nthe decrypted message:\n%s\n",decrypted_mes);
	getchar();
	return 0;
}
예제 #6
0
void DEC3_Decrypt(unsigned char *miwen, unsigned char *out_buf)
{
	unsigned char buf1[8],buf2[8];

    DES_Decrypt(&DES_key[0],miwen,buf1);
	DES_Encrypt(&DES_key[8],buf1,buf2);
    DES_Decrypt(&DES_key[0],buf2,out_buf);
}
예제 #7
0
파일: enfileTest.cpp 프로젝트: yzmin/Des
int main(int argc,char **argv)
{
	if(argc < 4)
	{
		printf("./enfile seckey enkey dekey\n");
		return -1;
	}	
	printf("开始加密!\n");
	DES_Encrypt(argv[1],"12345678",argv[2]);
	printf("加密完成!\n");	
	DES_Decrypt(argv[2],"12345678",argv[3]);
	printf("解密完成!\n");

	return 0;
}
예제 #8
0
파일: task2.c 프로젝트: LaneTee/xmega-intro
int main( void )
{
	bool success = true;

	/* Example of how to use 3DES encryption and decryption functions. */
	DES_3DES_Encrypt(indata, cipherdata, deskeys);
	DES_3DES_Decrypt(cipherdata, outdata, deskeys);

	/* Check if decrypted answer is equal to plaintext. */
	for (uint8_t i = 0; i < DES_BLOCK_LENGTH ; i++ ){
		if (indata[i] != outdata[i]){
			success = false;
			break;
		}
	}

	/* "Manual" 3DES decryption implenemtation */
	/* cipher -> DES_DK3 -> DES_EK2 -> DES_DK1 -> plaintext */

	DES_Decrypt();  /* Add Code */
	DES_Encrypt();  /* Add Code */
	DES_Decrypt();  /* Add Code */


	/* Check if this "manual" decrypt is equal to indata */
	for (uint8_t i = 0; i < DES_BLOCK_LENGTH ; i++ ){
		if (indata[i] != des_stage_3[i]){
			success = false;
			break;
		}
	}

	if (success){
	  	while (true){
		/* If the example ends up here everything is ok. */
             nop();
		}
	}else{
		while (true){
		/* If the example ends up here something is wrong. */
             nop();
		}
	}
}
예제 #9
0
int main()  
{     
	clock_t a,b;  
	char *key = "ABCDEFGH12345678";
	char tmp[100] ={0};
	char tmp_2[100] ={0};

	char *plainStr = "12345678abcdefgh1";
	long int n_plain,n_cipher = 0;
	
	a = clock();  
	DES_Encrypt("1.txt",key,"2.txt");  
	b = clock();  
	printf("¼ÓÃÜÏûºÄ%dºÁÃë\n",b-a);  
	  
	system("pause");  
	a = clock();  
	DES_Decrypt("2.txt",key,"3.txt");  
	b = clock();  
	printf("½âÃÜÏûºÄ%dºÁÃë\n",b-a);  
	getchar(); 
	

	DES_Encrypt_Data(plainStr,key,tmp,16);
	printf("data len is %d\n",n_cipher);

	
	DES_Decrypt_Data(tmp, key,tmp_2,16);
	
	printf("data decrypted is %s\n",tmp_2);
	

	getchar(); 
	
	return 0;  
}