• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ decrypt函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: main

int main (int argc, char *argv[]) {
	Card deck[DECK_SIZE];
	Card starting_deck[DECK_SIZE];

	char in_message[MAX_MESSAGE_LENGTH];
	char out_message[MAX_MESSAGE_LENGTH];
	int mode = 0; //encrypt = 0, decrypt = 1

	if (argc != 1) {
		printf("usage: SolitareEncryption1\n");
		printf("SEKEY environment variable must be set to the key value\n");
		exit(1);
	}

	init_deck(starting_deck);
	while (1) {
		//set the deck to the key starting position
		memcpy(deck, starting_deck, sizeof(Card) * DECK_SIZE);
		print_deck(deck);
		if (!mode) {
			printf("Enter message to be encrypted (type '/help' for help):\n");
		} else {
			printf("Enter message to be decrypted (type '/help' for help):\n");
		}
		fflush(stdout);
		if (fgets(in_message, MAX_MESSAGE_LENGTH, stdin) == NULL) {
			printf("fgets failure\n");
			exit(1);
		}

		//get rid of the newline from fgets
		int i;
		for (i = 0; in_message[i] != '\0'; i++) {
			if (in_message[i] == '\n') {
				in_message[i] = '\0';
				break;
			}
		}
		if (!strcmp(in_message, "/quit")) {
			break;
		} else if (!strcmp(in_message, "/encrypt")) {
			mode = 0;
			printf("Encryption mode\n");
		} else if (!strcmp(in_message, "/decrypt")) {
			mode = 1;
			printf("Decryption mode\n");
		} else if (!strcmp(in_message, "/help")) {
			printf("/encrypt: switch to encryption mode\n"
				   "/decrypt: switch to decryption mode\n"
				   "/quit: quit program\n");
		} else {
			if (!mode) {
				printf("Unencrypted: %s\n", in_message);
				printf("Encrypted: %s\n",
						encrypt(deck, in_message, out_message));
			} else {
				printf("Encrypted: %s\n", in_message);
				printf("Decrypted: %s\n",
						decrypt(deck, in_message, out_message));
			}
		}
	}
	return 0;
}
开发者ID:trend-infosec-public,项目名称:sca_public_test_code,代码行数:64,代码来源:solitaire.c


示例2: process_discovery

static void process_discovery(uint8_t sock, Remote_Info *remote_info, WIZnet_Header *wiznet_header)
{
    uint16_t len;
    uint8_t buffer[sizeof(WIZnet_Header) + sizeof(WIZnet_Discovery_Mixed_Condition)];	// header + most biggest structure
    uint32_t ptr;
    WIZnet_Discovery_Reply reply;
    S2E_Packet *s2e_packet = get_S2E_Packet_pointer();
    uint8_t ip[4];
    uint16_t port;

    getsockopt(sock, SO_REMAINSIZE, &len);
    if(len != wiznet_header->length)
        return;

    switch(wiznet_header->op_code[0]) {
    case DISCOVERY_ALL:
        break;

    case DISCOVERY_PRODUCT_CODE:
    {
        WIZnet_Discovery_Product_Code product_code;
        recvfrom(sock, (uint8_t *)&product_code, sizeof(WIZnet_Discovery_Product_Code), ip, &port);

        if((wiznet_header->valid & 0x80))
            decrypt((wiznet_header->valid & 0x7F), (uint8_t *)&product_code, len);

        if(memcmp(product_code.product_code, s2e_packet->module_type, 3))
            return;
        break;
    }

    case DISCOVERY_MAC_ADDRESS:
    {
        WIZnet_Discovery_MAC_Address mac_address;
        recvfrom(sock, (uint8_t *)&mac_address, sizeof(WIZnet_Discovery_MAC_Address), ip, &port);

        if((wiznet_header->valid & 0x80))
            decrypt((wiznet_header->valid & 0x7F), (uint8_t *)&mac_address, len);

        if(   mac_address.start_mac_address[0] > s2e_packet->network_info_common.mac[0]
                || mac_address.start_mac_address[1] > s2e_packet->network_info_common.mac[1]
                || mac_address.start_mac_address[2] > s2e_packet->network_info_common.mac[2]
                || mac_address.start_mac_address[3] > s2e_packet->network_info_common.mac[3]
                || mac_address.start_mac_address[4] > s2e_packet->network_info_common.mac[4]
                || mac_address.start_mac_address[5] > s2e_packet->network_info_common.mac[5])
            return;
        if(   mac_address.end_mac_address[0] < s2e_packet->network_info_common.mac[0]
                || mac_address.end_mac_address[1] < s2e_packet->network_info_common.mac[1]
                || mac_address.end_mac_address[2] < s2e_packet->network_info_common.mac[2]
                || mac_address.end_mac_address[3] < s2e_packet->network_info_common.mac[3]
                || mac_address.end_mac_address[4] < s2e_packet->network_info_common.mac[4]
                || mac_address.end_mac_address[5] < s2e_packet->network_info_common.mac[5])
            return;
        break;
    }

    case DISCOVERY_ALIAS:
    {
        WIZnet_Discovery_Alias alias;
        recvfrom(sock, (uint8_t *)&alias, sizeof(WIZnet_Discovery_Alias), ip, &port);

        if((wiznet_header->valid & 0x80))
            decrypt((wiznet_header->valid & 0x7F), (uint8_t *)&alias, len);

        if(memcmp(alias.alias, s2e_packet->module_name, strlen((char *)alias.alias)))
            return;
        break;
    }

    case DISCOVERY_MIXED_COND:
    {
        WIZnet_Discovery_Mixed_Condition mixed_condition;
        recvfrom(sock, (uint8_t *)&mixed_condition, sizeof(WIZnet_Discovery_Mixed_Condition), ip, &port);

        if((wiznet_header->valid & 0x80))
            decrypt((wiznet_header->valid & 0x7F), (uint8_t *)&mixed_condition, len);

        break;
    }

    default:
        return;
    }

    // reply
    wiznet_header->length = sizeof(WIZnet_Discovery_Reply);
    wiznet_header->op_code[1] = WIZNET_REPLY;

    memcpy(reply.product_code, s2e_packet->module_type, 3);
    memcpy(reply.fw_version, s2e_packet->fw_ver, 3);
    memcpy(reply.mac_address, s2e_packet->network_info_common.mac, 6);

    if((wiznet_header->valid & 0x80))
        encrypt((wiznet_header->valid & 0x7F), (uint8_t *)&reply, sizeof(WIZnet_Discovery_Reply));

    ptr = 0;
    memcpy(buffer, wiznet_header, sizeof(WIZnet_Header));
    ptr += sizeof(WIZnet_Header);
    memcpy(buffer + ptr, (void *)&reply, sizeof(WIZnet_Discovery_Reply));
    ptr += sizeof(WIZnet_Discovery_Reply);
//.........这里部分代码省略.........
开发者ID:xd785,项目名称:WIZ550web,代码行数:101,代码来源:ConfigMessage.c


示例3: encrypt

    return stream
        << credential.m_serverUuid
        << credential.m_userName
        << credential.m_login
        << encrypt( credential.m_password );
}

QDataStream& operator >>( QDataStream& stream, ServerCredential& credential )
{
    QByteArray password;
    stream
        >> credential.m_serverUuid
        >> credential.m_userName
        >> credential.m_login
        >> password;
    credential.m_password = decrypt( password );
    return stream;
}

HttpCredential::HttpCredential()
{
}

HttpCredential::HttpCredential( const QString& hostName, const QString& login, const QString& password ) :
    m_hostName( hostName ),
    m_login( login ),
    m_password( password )
{
}

HttpCredential::~HttpCredential()
开发者ID:Herysutrisno,项目名称:webIssue,代码行数:31,代码来源:credential.cpp


示例4: result

SafeString<char> ProtectedBuffer::toString(){
	SafeString<char> result(data.begin(), data.end());
	decrypt(const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(result.data())), result.size());
	return result;
}
开发者ID:j-kubik,项目名称:libkeepass2pp,代码行数:5,代码来源:platform_other.cpp


示例5: main

int main(int argc, char**argv)
{
int n;
char sendline[10000];
char recvline[10000];
char key[32];
memset(key,'\0',32);
unsigned char decrypted[10000];

FILE *file;
//memset(recvline,'\0',10000);
//char user_input[1000];
file=fopen(argv[1],"r");
char *split=strtok(argv[1],".");
split=strtok(NULL,".");
if(file==0 || strcmp(split,"bank")) {
    printf("Error opening ATM initialization file\n");
    return 64;
}

fread(key,sizeof(key),32,file);
key[32]='\0';
//printf("bank file contents: %s\n",key);
HashTable *users = hash_table_create(100);
HashTable *balance = hash_table_create(100);
Bank *bank = bank_create();
//bank->users = list_create();
//bank->usr_key = hash_table_create(100);
//bank->usr_bal = hash_table_create(100);
printf("%s", prompt);
fflush(stdout);

while(1)
{
    memset(decrypted,'\0',10000);
    memset(recvline,'\0',10000);
    //memset(sendline,'\0',10000);
    fd_set fds;
    FD_ZERO(&fds);
    FD_SET(0, &fds);
    FD_SET(bank->sockfd, &fds);
    select(bank->sockfd+1, &fds, NULL, NULL, NULL);

    if(FD_ISSET(0, &fds)) {
        fgets(sendline, 10000,stdin);
        bank_process_local_command(bank, sendline, strlen(sendline),users,balance);
        printf("%s", prompt);
        fflush(stdout);
    } else if(FD_ISSET(bank->sockfd, &fds)) {
        ;
        //int flag = 0;

        n = bank_recv(bank, recvline, 10000);


        //int flag=decrypt(recvline,key,decrypted,n);

        if(!decrypt(recvline,key,decrypted,n)) { //this means that it has not been decrypted correctly so it will return a null packet
            unsigned char encrypted[10000];
            char packet[10000];
            sprintf(packet,"<%s>",NULL);
            int out_size =0;
            encrypt(packet,key,encrypted,&out_size);
            bank_send(bank, encrypted, out_size);
            printf("%s", prompt);
            fflush(stdout);
            continue;
        }

        //printf("%s\n",decrypted);
        char * message=strtok(decrypted,"\n");

        bank_process_remote_command(bank, message, n, users,key,balance);

    }

}
hash_table_free(balance);
hash_table_free(users); //never executes
bank_free(bank);
//fclose(file);

return EXIT_SUCCESS;
}
开发者ID:scmilburn,项目名称:ATM,代码行数:84,代码来源:bank-main.c


示例6: main

// Main method of HW5, mostly taking user input and running the correct prog
int main(int argc, char *argv[]) {

	// Look for correct command line arguments
	if(argc <= 1) {
		usage();
		return 0;
	} else {
		if(strcmp(argv[1], "tablecheck") == 0) {
			// Tablecheck prog should be run
			FILE* tablefile = NULL;
			for(int i=2; i<argc; i++) {
				if(strncmp(argv[i], "-t=", 3) == 0) {
					tablefile = fopen(argv[i]+3, "r");
					if(tablefile == NULL) {
						fprintf(stderr, "ERROR: invalid file '%s' for reading.\n", argv[i]+3);
						return 0;
					}
				}
			}
			if(tablefile) {
				tablecheck(tablefile);
				fclose(tablefile);
			} else {
				usage("tablecheck");
			}
		}
		else if(strcmp(argv[1], "encrypt") == 0) {
			// Encrypt prog should be run
			char *key = NULL;
			FILE* tablefile = NULL;
			for(int i=2; i<argc; i++) {
				if(strncmp(argv[i], "-k=", 3) == 0) {
					key = argv[i]+3;
				}
				else if(strncmp(argv[i], "-t=", 3) == 0) {
					tablefile = fopen(argv[i]+3, "r");
					if(tablefile == NULL) {
						fprintf(stderr, "ERROR: invalid file '%s' for reading.\n", argv[i]+3);
						return 0;
					}
				}
			}
			if(key && tablefile) {
				if(argv[argc-1][0] != '-') {
					// Take input from file
					FILE* fin = NULL;
					fin = fopen(argv[argc-1], "r");
					if(fin == NULL) {
						fprintf(stderr, "ERROR: invalid file '%s' for reading.\n", argv[argc-1]);
						return 0;
					}
					encrypt(key, tablefile, fin);
					fclose(fin);
				} else {
					// Take input from cmd line
					encrypt(key, tablefile, stdin);
				}
				fclose(tablefile);
			} else {
				usage("encrypt");
			}
		}
		else if(strcmp(argv[1], "decrypt") == 0) {
			// Decrypt prog should be run
			char *key = NULL;
			FILE* tablefile = NULL;
			for(int i=2; i<argc; i++) {
				if(strncmp(argv[i], "-k=", 3) == 0) {
					key = argv[i]+3;
				}
				else if(strncmp(argv[i], "-t=", 3) == 0) {
					tablefile = fopen(argv[i]+3, "r");
					if(tablefile == NULL) {
						fprintf(stderr, "ERROR: invalid file '%s' for reading.\n", argv[i]+3);
						return 0;
					}
				}
			}
			if(key && tablefile) {
				if(argv[argc-1][0] != '-') {
					// Take input from file
					FILE* fin = NULL;
					fin = fopen(argv[argc-1], "r");
					if(fin == NULL) {
						fprintf(stderr, "ERROR: invalid file '%s' for reading.\n", argv[argc-1]);
						return 0;
					}
					decrypt(key, tablefile, fin);
					fclose(fin);
				} else {
					// Take input from cmd line
					decrypt(key, tablefile, stdin);
				}
				fclose(tablefile);
			} else {
				usage("decrypt");
			}
		}
		else if(strcmp(argv[1], "encrypt3") == 0) {
//.........这里部分代码省略.........
开发者ID:kevincrane,项目名称:cryptography-projects,代码行数:101,代码来源:hw5.c


示例7: main


//.........这里部分代码省略.........
			break;
		case 'x':
			xfile = optarg;
			break;
		default:
			usage(NULL);
			break;
		}
	}
	argc -= optind;
	argv += optind;

	if (argc != 0)
		usage(NULL);

	switch (verb) {
	case ENCRYPT:
	case DECRYPT:
		if (!msgfile)
			usage("You must specify a message-file");
		if (!xfile) {
			if (strcmp(msgfile, "-") == 0)
				usage("must specify encfile with - message");
			if (snprintf(xfilebuf, sizeof(xfilebuf), "%s.enc",
			    msgfile) >= sizeof(xfilebuf))
				errx(1, "path too long");
			xfile = xfilebuf;
		}
		break;
	case SIGN:
	case VERIFY:
		if (!xfile && msgfile) {
			if (strcmp(msgfile, "-") == 0)
				usage("must specify sigfile with - message");
			if (snprintf(xfilebuf, sizeof(xfilebuf), "%s.sig",
			    msgfile) >= sizeof(xfilebuf))
				errx(1, "path too long");
			xfile = xfilebuf;
		}
		break;
	default:
		break;
	}

	switch (verb) {
	case DECRYPT:
		decrypt(pubkeyfile, seckeyfile, msgfile, xfile);
		break;
	case ENCRYPT:
		if (seckeyfile && (!pubkeyfile && !ident))
			usage("specify a pubkey or ident");
		if (pubkeyfile || ident) {
			if (v1compat)
				v1pubencrypt(pubkeyfile, ident, seckeyfile, msgfile, xfile, binary);
			else
				pubencrypt(pubkeyfile, ident, seckeyfile, msgfile, xfile, binary);
		} else
			symencrypt(msgfile, xfile, binary);
		break;
	case GENERATE:
		if (!ident && !(ident= getenv("USER")))
			ident = "unknown";

		/* can specify none, but not only one */
		if ((!pubkeyfile && seckeyfile) ||
		    (!seckeyfile && pubkeyfile))
			usage("must specify pubkey and seckey");
		/* if none, create ~/.reop */
		if (!pubkeyfile && !seckeyfile) {
			char buf[1024];
			const char *home;

			if (!(home = getenv("HOME")))
				errx(1, "can't find HOME");
			snprintf(buf, sizeof(buf), "%s/.reop", home);
			if (mkdir(buf, 0700) == -1 && errno != EEXIST)
				err(1, "Unable to create ~/.reop");
		}
		generate(pubkeyfile, seckeyfile, ident, password);
		break;
	case SIGN:
		if (!msgfile)
			usage("must specify message");
		signfile(seckeyfile, msgfile, xfile, embedded);
		break;
	case VERIFY:
		if (!msgfile && !xfile)
			usage("must specify message or sigfile");
		if (msgfile)
			verifysimple(pubkeyfile, msgfile, xfile, quiet);
		else
			verifyembedded(pubkeyfile, xfile, quiet);
		break;
	default:
		usage(NULL);
		break;
	}

	return 0;
}
开发者ID:jpouellet,项目名称:reop,代码行数:101,代码来源:main.c


示例8: decrypt

 Coin<FIELD> decrypt(const AddrPair<FIELD>& addr) const {
     return decrypt(addr.secretAddr(), addr.publicAddr());
 }
开发者ID:jancarlsson,项目名称:kapital,代码行数:3,代码来源:EncryptedCoin.hpp


示例9: traiter_recu

int traiter_recu (char * requete_recu)
{
	unsigned char requete_decrypt[sizeof(requete_recu)];
	puts("YIHI");
	decrypt(requete_recu, requete_decrypt, strlen(requete_recu));
	printf("JAI RECU -> %s\n", requete_recu);
	printf("DECRYPT -> %s\n", requete_decrypt);

	char *type = malloc (sizeof (char*) * 256);
	char *donnee = malloc (sizeof (char*) * 256);
	char * save_ptr;

	type = strtok_r(requete_decrypt, "*", &save_ptr);

	int j = 0;

	/*while (*save_ptr != '\0')	
	{
		donnee[j] = *(save_ptr++);
		j++;
	}*/

	//if (type[0] == 'R') printf("DONNEE de la reponse -> %s\n", donnee);


	switch(type[0])
	{
		case 'R' :
				  while (*save_ptr != '\0')	
				  {
					donnee[j] = *(save_ptr++);
					j++;
				  }
				printf("DONNEE de la reponse -> %s\n", donnee);
				break;

		case '1' :
				;

				char *status_requete = malloc (sizeof (char*) * 1024);
				char *test = malloc (sizeof (char*) * 1024);
				char *nom = recup_valeur("nom");
				printf("NOM -> %s\n", nom);
				//char *status = recup_valeur("status");
				printf("RECUP_STATUS -> %s\n", recup_valeur("status"));
				status_requete = strtok_r(NULL, "*", &save_ptr);
				test = strtok_r(NULL, "*", &save_ptr);
				//printf("TEST -> %s\n", test);
				printf("STATUS -> %s\n", status_requete);
				
				if( strcmp(recup_valeur("status"), status_requete) == 0)
				{
					puts("Correspond");
					unsigned char a_envoyer[sizeof (char *) * 1024];
					sprintf(a_envoyer, "1*%s*%s", nom, recup_valeur("status"));
					unsigned char a_envoyer_crypt[sizeof(a_envoyer)];
					crypt(a_envoyer, a_envoyer_crypt, strlen(a_envoyer));
					envoi_requete(a_envoyer_crypt);
				}
				else
				{
					puts("NOP");
					unsigned char a_envoyer[sizeof (char *) * 1024];
					sprintf(a_envoyer, "1*none");
					unsigned char a_envoyer_crypt[sizeof(a_envoyer)];
					crypt(a_envoyer, a_envoyer_crypt, strlen(a_envoyer));
					envoi_requete(a_envoyer_crypt);	
				}
				break;

	}
	return 0;

}
开发者ID:Ektoplasma,项目名称:frontale,代码行数:74,代码来源:traitement_recu.c


示例10: decrypt

 void decrypt(const char* in, std::size_t len, uint8_t* out)
 {
     decrypt(reinterpret_cast<const uint8_t*>(in), len, out);
 }
开发者ID:wumch,项目名称:pvdesktop,代码行数:4,代码来源:Crypto.hpp


示例11: main

int main(int argc, char *argv[])
{
        FILE *rsapub_key_fp;
        unsigned char *cam128_key, *cam128_iv;
        unsigned char *cipher_of_secret_text, *cipher_of_signed_key, *signed_key, *secret_text, *clobbered_key;
        EVP_PKEY *rsapub_key;
        unsigned char *rc4_40_key;
        const EVP_CIPHER *cam128_cfb8, *rc4_40;
        const EVP_MD *sha;
        EVP_MD_CTX sha_ctx;
        int cam128_cfb8_keylen, cam128_cfb8_ivlen, rc4_40_keylen, signed_key_size;
        int ret, count;
        long cipher_of_signed_key_size, clobbered_key_size, cipher_of_secret_text_size,  secret_text_size;

        // get the parameters for CAMELLIA128_cfb8
        cam128_cfb8 = EVP_camellia_128_cfb8();
        cam128_cfb8_keylen = EVP_CIPHER_key_length(cam128_cfb8);
        cam128_cfb8_ivlen = EVP_CIPHER_iv_length(cam128_cfb8);

        // get the parameters for RC4_40
        rc4_40 = EVP_rc4_40();
        rc4_40_keylen = EVP_CIPHER_key_length(rc4_40);

        // get the parameters for sha
        sha = EVP_sha();

        // read the s67766-clobbered-key.bin and store the key and iv for CAMELLIA128-cfb8
        cam128_key = malloc(cam128_cfb8_keylen);
        cam128_iv = malloc(cam128_cfb8_ivlen);

        clobbered_key_size = read_file(clobbered_key_file, &clobbered_key);
        if(clobbered_key_size != cam128_cfb8_keylen+cam128_cfb8_ivlen)
        {
                printf("reading file %s returned not enough Bytes: %ld, instead of: %d\n", clobbered_key_file, clobbered_key_size, cam128_cfb8_keylen+cam128_cfb8_ivlen);
                perror("");
        }
        memcpy(cam128_key, clobbered_key, cam128_cfb8_keylen);
        memcpy(cam128_iv, clobbered_key+cam128_cfb8_keylen, cam128_cfb8_ivlen);

        // read the s67766-cipher-of-signed-key.bin
        cipher_of_signed_key_size = read_file(cipher_of_signed_key_file, &cipher_of_signed_key);

        // read the public key from rsapub.pem
        rsapub_key_fp = fopen(rsapub_key_file, "r");
        if (!rsapub_key_fp)
        {
                printf("opening file %s returned error\n", rsapub_key_file);
                perror("");
        }

        rsapub_key = PEM_read_PUBKEY(rsapub_key_fp, NULL, NULL, NULL);
        if (!rsapub_key)
        {
                printf("PEM_read_PUBKEY returned error for RSA\n");
        }

        if(fclose(rsapub_key_fp) != 0)
        {
                printf("closing file %s returned error\n", rsapub_key_file);
                perror("");
        }

        // restore the clobbered key with bruteforce
        signed_key = malloc(cipher_of_signed_key_size);
        for(count = 0; count<=255; count++)
        {
                memset(cam128_key, count, 1);

                //decrypt the cipher with guessed key
                signed_key_size =  decrypt(cam128_cfb8, &signed_key, cipher_of_signed_key, cipher_of_signed_key_size, cam128_key, cam128_iv);
                if(signed_key_size==-1)
                {
                        return -1;
                }

                if(EVP_VerifyInit(&sha_ctx, sha) == 0)
                {
                        printf("EVP_VerifyInit returned error for SHA\n");
                }
                if(EVP_VerifyUpdate(&sha_ctx, signed_key, rc4_40_keylen) == 0)
                {
                        printf("EVP_VerifyUpdate returned error for SHA\n");
                }
                ret = EVP_VerifyFinal(&sha_ctx, signed_key+rc4_40_keylen, signed_key_size-rc4_40_keylen, rsapub_key);
                switch(ret)
                {
                        case -1:
                                printf("EVP_VerifyFinal returned error for SHA\n");
                                break;
                        case 0:
                                break;
                        case 1:
                                count = 255;
                                break;
                }
        }
        // extract the key for RC-4 40
        rc4_40_key = malloc(rc4_40_keylen);
        memcpy(rc4_40_key, signed_key, rc4_40_keylen);

//.........这里部分代码省略.........
开发者ID:mYstar,项目名称:ITSEC,代码行数:101,代码来源:s67766.c


示例12: main

int main() {
	srand((unsigned)time(NULL));
	int i;
	EC_KEY* key;
	//key = EC_KEY_new_by_curve_name(415);
	key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
	const EC_GROUP *group = EC_KEY_get0_group(key);
	if (EC_KEY_generate_key(key)==0) {
		printf("Error generate key\n");
		return -1;
	}
	unsigned char pk_b[33];
	const EC_POINT *pub = EC_KEY_get0_public_key(key);
	if (EC_POINT_point2oct(group, pub, POINT_CONVERSION_COMPRESSED, pk_b, 33, 0)!=33) {
		printf("Error 2\n");
		return -1;
	}
	unsigned char h1[16],h2[16];

	printf("\x02");
	for (i=0;i<16;i++) {
		h1[i]=rand()%256;
		printf("%c",h1[i]);
	}
	for (i=0;i<33;i++)
		printf("%c",pk_b[i]);
	fflush(stdout);
	//get h2
	for (i=0;i<16;i++) 
		h2[i]=rand()%256;
	for (i=0;i<16;i++)
		scanf("%c",&h2[i]);
		
	//get peerpk_b
	unsigned char peerpk_b[33]={2 , 30 , 25 , 50 , 17 , 242 , 232 , 55 , 157 , 18 , 106 , 115 , 214 , 193 , 192 , 39 , 207 , 226 , 184 , 216 , 244 , 147 , 111 , 188 , 125 , 230 , 38 , 125 , 231 , 50 , 56 , 152 , 148 };
	for (i=0;i<33;i++)
		scanf("%c",&peerpk_b[i]);
	
	EC_POINT *peerpk = EC_POINT_new(group);
	if (EC_POINT_oct2point(group, peerpk, peerpk_b, 33, 0)==0) {
		printf("Error 3\n");
		return -1;
	}
	unsigned char skey[33];
	if (ECDH_compute_key(skey, 32,  peerpk, key, NULL)==0) {
		printf("Error 4\n");
		return -1;
	}


	SHA512_CTX shactx;	
	unsigned char hash[SHA512_DIGEST_LENGTH];
	SHA512_Init(&shactx);
	SHA512_Update(&shactx, h2, 16);
	SHA512_Update(&shactx, skey, 32);
	SHA512_Update(&shactx, h1, 16);
	SHA512_Final(hash, &shactx);

	for (i=0;i<64;i++)
		printf("%02x",hash[i]);	
	fflush(stdout);

	struct cipher c;
	c.recvfd=0;
	c.sendfd=1;
	for (i=0;i<16;i++)
		c.sendkey[i]=hash[i];
	for (i=0;i<4;i++)
		c.sendiv[i]=hash[32+i];
	for (i=0;i<16;i++)
		c.recvkey[i]=hash[16+i];
	for (i=0;i<4;i++)
		c.recviv[i]=hash[36+i];
	c.sendcnt=0;
	c.recvcnt=0;

	unsigned char d[1000];
	unsigned char oiv[8];
	int op;
	char dlen;

	while (true) {
		scanf("%d",&op);
		scanf("%c",&dlen);
		scanf("%c",&dlen);
		for (i=0;i<dlen;i++)
			scanf("%c",&d[i]);
		if (op==1) {
			for (i=0;i<8;i++)
				oiv[i]=rand()%256;
			encrypt(c,d,dlen,oiv);
			c.recvcnt+=1;
		} else if (op==2) {
			for (i=0;i<8;i++)
				scanf("%c",&oiv[i]);
			decrypt(c,d,dlen,oiv, NULL);
			c.sendcnt+=1;
		}
		fflush(stdout);
	}
//.........这里部分代码省略.........
开发者ID:Septyem,项目名称:CTF-writeups,代码行数:101,代码来源:openssl.cpp


示例13: initLDAP

//-----------------------------------------------------
//
//-----------------------------------------------------
bool initLDAP(IPropertyTree * ldapProps)
{
    StringAttr serverType( ldapProps->queryProp("@serverType") );
    if (!serverType.length())
    {
        fprintf(stderr, "\nERROR: serverType not set in LDAPServer component");
        return false;
    }

    StringBuffer hpccUser;
    StringBuffer hpccPwd;
    ldapProps->getProp("@systemUser", hpccUser);
    ldapProps->getProp("@systemPassword", hpccPwd);
    if (0==hpccUser.length() || 0==hpccPwd.length())
    {
        fprintf(stderr, "\nERROR: HPCC systemUser credentials not found in configuration");
        return false;
    }

    StringBuffer ldapAddress;
    ldapProps->getProp("@ldapAddress", ldapAddress);

    //Get LDAP admin creds from user
    char buff[100];
    fprintf(stdout, "\nEnter the '%s' LDAP Admin User name on '%s'...",serverType.get(),ldapAddress.str());
    do
    {
        char * line = fgets(buff, sizeof(buff), stdin);
        if (!line)
            return false;
    }
    while (buff[0] == (char)'\n');

    if (buff[strlen(buff)-1] == '\n')
        buff[strlen(buff)-1] = (char)NULL;
    StringAttr ldapUser(buff);

    fprintf(stdout, "Enter the LDAP Admin user '%s' password...",ldapUser.get());
    char * line = fgets(buff, sizeof(buff), stdin);
    if (!line)
        return false;

    if (buff[strlen(buff)-1] == '\n')
        buff[strlen(buff)-1] = (char)NULL;
    StringAttr ldapPwd(buff);
    if (0==ldapUser.length() || 0==ldapPwd.length())
    {
        fprintf(stderr, "\nERROR: Invalid LDAP Admin account credentials entered");
        return false;
    }

    fprintf(stdout, "\nReady to initialize HPCC LDAP Environment, using the following settings");
    fprintf(stdout, "\n\tLDAP Server     : %s", ldapAddress.str());
    fprintf(stdout, "\n\tLDAP Type       : %s", serverType.get());
    fprintf(stdout, "\n\tHPCC Admin User : %s", hpccUser.str());
    fprintf(stdout, "\nProceed?  y/n ");
    for (;;)
    {
        int c = getchar();
        if (c == 'y' || c == 'Y')
            break;
        else if (c == 'n' || c == 'N')
            return true;
    }

    if (stricmp(serverType.get(),"ActiveDirectory"))
        ldapProps->setProp("@systemBasedn", "");

    //Replace system user with LDAP Admin credentials
    ldapProps->setProp("@systemUser", ldapUser);
    ldapProps->setProp("@systemCommonName", ldapUser);
    StringBuffer sb;
    encrypt(sb,ldapPwd);
    ldapProps->setProp("@systemPassword", sb.str());

    //Create security manager. This creates the required OUs
    Owned<ISecManager> secMgr;
    try
    {
        secMgr.setown(newLdapSecManager("initldap", *LINK(ldapProps)));
    }
    catch(IException *e)
    {
        StringBuffer buff;
        e->errorMessage(buff);
        e->Release();
        fprintf(stderr, "\nERROR: Unable to create security manager : %s", buff.str());
        return false;
    }

    //Create HPCC Admin user
    Owned<ISecUser> user = secMgr->createUser(hpccUser.str());
    StringBuffer pwd;
    decrypt(pwd, hpccPwd.str());
    user->credentials().setPassword(pwd.str());
    try { secMgr->addUser(*user.get()); }
    catch(...) {}//user may already exist, so just move on
//.........这里部分代码省略.........
开发者ID:RogerDev,项目名称:HPCC-Platform,代码行数:101,代码来源:initldap.cpp


示例14: decrypt

bool CMyPlug::importTerrainData(iSceneData * pSceneData, const std::string& strFilename)
{
	pSceneData->clear();
	if (pSceneData->resize(253,253))
	{
		// EncTerrain
		IOReadBase* pRead = IOReadBase::autoOpen(strFilename);
		if (pRead)
		{
			if (MAP_FILE_SIZE==pRead->GetSize())
			{
				char buffer[MAP_FILE_SIZE];
				pRead->Read(buffer,MAP_FILE_SIZE);
				decrypt(buffer,MAP_FILE_SIZE);
				char* p = buffer;
				unsigned short uMuFlgMap = *((unsigned short*)p);
				p+=2;
				for (int y=0; y<253; ++y)
				{
					for (int x=0; x<253; ++x)
					{
						pSceneData->setCellTileID(x,y,*p,0);
						p++;
					}
					p+=3;
				}
				p+=256*3;
				for (int y=0; y<253; ++y)
				{
					for (int x=0; x<253; ++x)
					{
						pSceneData->setCellTileID(x,y,*p,1);
						p++;
					}
					p+=3;
				}
				p+=256*3;
				for (int y=0; y<254; ++y)
				{
					for (int x=0; x<254; ++x)
					{
						pSceneData->setVertexColor(x,y,Color32(*p,255,255,255));
						p++;
					}
					p+=2;
				}
			}
			IOReadBase::autoClose(pRead);
		}
		// EncTerrain.att
		pRead = IOReadBase::autoOpen(ChangeExtension(strFilename,".att"));
		if (pRead)
		{
			if (ATT_FILE_129KB_SIZE==pRead->GetSize())
			{
				char buffer[ATT_FILE_129KB_SIZE];
				pRead->Read(buffer,ATT_FILE_129KB_SIZE);
				decrypt(buffer,ATT_FILE_129KB_SIZE);
				decrypt2(buffer,ATT_FILE_129KB_SIZE);
				char* p = buffer;
				unsigned long uMuFlgAtt = *((unsigned long*)p);
				p+=4;
				for (int y=0; y<253; ++y)
				{
					for (int x=0; x<253; ++x)
					{
						pSceneData->setCellAttribute(x,y,*p);
						p+=2;
					}
					p+=6;
				}
			}
			else if (ATT_FILE_65KB_SIZE==pRead->GetSize())
			{
				char buffer[ATT_FILE_65KB_SIZE];
				pRead->Read(buffer,ATT_FILE_65KB_SIZE);
				decrypt(buffer,ATT_FILE_65KB_SIZE);
				decrypt2(buffer,ATT_FILE_65KB_SIZE);
				char* p = buffer;
				unsigned long uMuFlgAtt = *((unsigned long*)p);
				p+=4;
				for (int y=0; y<253; ++y)
				{
					for (int x=0; x<253; ++x)
					{
						pSceneData->setCellAttribute(x,y,*p);
						p++;
					}
					p+=3;
				}
			}
			IOReadBase::autoClose(pRead);
		}
		// TerrainHeight
		std::string strHeightFilename = GetParentPath(strFilename)+"TerrainHeight.ozb";
		pRead = IOReadBase::autoOpen(strHeightFilename);
		if (pRead)
		{
			if (HEIGHT_HEAD_SIZE+HEIGHT_BUFFER_SIZE<=pRead->GetSize())
			{
//.........这里部分代码省略.........
开发者ID:constantinbogdan,项目名称:node3d,代码行数:101,代码来源:Terrain.cpp


示例15: qWarning


//.........这里部分代码省略.........
    else {
        // any other irc command
        QString typeName = QLatin1String("IrcEvent") + cmd.at(0).toUpper() + cmd.mid(1).toLower();
        type = eventManager()->eventTypeByName(typeName);
        if (type == EventManager::Invalid) {
            type = eventManager()->eventTypeByName("IrcEventUnknown");
            Q_ASSERT(type != EventManager::Invalid);
        }
        target = QString();
    }

    // Almost always, all params are server-encoded. There's a few exceptions, let's catch them here!
    // Possibly not the best option, we might want something more generic? Maybe yet another layer of
    // unencoded events with event handlers for the exceptions...
    // Also, PRIVMSG and NOTICE need some special handling, we put this in here as well, so we get out
    // nice pre-parsed events that the CTCP handler can consume.

    QStringList decParams;
    bool defaultHandling = true; // whether to automatically copy the remaining params and send the event

    switch (type) {
    case EventManager::IrcEventPrivmsg:
        defaultHandling = false; // this might create a list of events

        if (checkParamCount(cmd, params, 1)) {
            QString senderNick = nickFromMask(prefix);
            QByteArray msg = params.count() < 2 ? QByteArray() : params.at(1);

            QStringList targets = net->serverDecode(params.at(0)).split(',', QString::SkipEmptyParts);
            QStringList::const_iterator targetIter;
            for (targetIter = targets.constBegin(); targetIter != targets.constEnd(); ++targetIter) {
                QString target = net->isChannelName(*targetIter) ? *targetIter : senderNick;

                msg = decrypt(net, target, msg);

                events << new IrcEventRawMessage(EventManager::IrcEventRawPrivmsg, net, msg, prefix, target, e->timestamp());
            }
        }
        break;

    case EventManager::IrcEventNotice:
        defaultHandling = false;

        if (checkParamCount(cmd, params, 2)) {
            QStringList targets = net->serverDecode(params.at(0)).split(',', QString::SkipEmptyParts);
            QStringList::const_iterator targetIter;
            for (targetIter = targets.constBegin(); targetIter != targets.constEnd(); ++targetIter) {
                QString target = *targetIter;

                // special treatment for welcome messages like:
                // :[email protected] NOTICE egst :[#apache] Welcome, this is #apache. Please read the in-channel topic message. This channel is being logged by IRSeekBot. If you have any question please see http://blog.freenode.net/?p=68
                if (!net->isChannelName(target)) {
                    QString decMsg = net->serverDecode(params.at(1));
                    QRegExp welcomeRegExp("^\\[([^\\]]+)\\] ");
                    if (welcomeRegExp.indexIn(decMsg) != -1) {
                        QString channelname = welcomeRegExp.cap(1);
                        decMsg = decMsg.mid(welcomeRegExp.matchedLength());
                        CoreIrcChannel *chan = static_cast<CoreIrcChannel *>(net->ircChannel(channelname)); // we only have CoreIrcChannels in the core, so this cast is safe
                        if (chan && !chan->receivedWelcomeMsg()) {
                            chan->setReceivedWelcomeMsg();
                            events << new MessageEvent(Message::Notice, net, decMsg, prefix, channelname, Message::None, e->timestamp());
                            continue;
                        }
                    }
                }
开发者ID:2kah,项目名称:quassel,代码行数:66,代码来源:ircparser.cpp


示例16: decrypt_file

void
decrypt_file (const gchar *input_file_path, const gchar *pwd)
{
    GError *err = NULL;

    goffset file_size = get_file_size (input_file_path);
    if (file_size == -1) {
        return;
    }
    if (file_size < (goffset) (sizeof (Metadata) + SHA512_DIGEST_SIZE)) {
        g_printerr ("The selected file is not encrypted.\n");
        return;
    }

    GFile *in_file = g_file_new_for_path (input_file_path);
    GFileInputStream *in_stream = g_file_read (in_file, NULL, &err);
    if (err != NULL) {
        g_printerr ("%s\n", err->message);
        // TODO
        return;
    }

    gchar *output_file_path;
    if (!g_str_has_suffix (input_file_path, ".enc")) {
        g_printerr ("The selected file may not be encrypted\n");
        output_file_path = g_strconcat (input_file_path, ".decrypted", NULL);
    }
    else {
        output_file_path = g_strndup (input_file_path, (gsize) g_utf8_strlen (input_file_path, -1) - 4); // remove .enc
    }
    GFile *out_file = g_file_new_for_path (output_file_path);
    GFileOutputStream *out_stream = g_file_append_to (out_file, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &err);
    if (err != NULL) {
        g_printerr ("%s\n", err->message);
        // TODO
        return;
    }

    Metadata *header_metadata = g_new0 (Metadata, 1);
    CryptoKeys *decryption_keys = g_new0 (CryptoKeys, 1);

    gssize rw_len = g_input_stream_read (G_INPUT_STREAM (in_stream), header_metadata, sizeof (Metadata), NULL, &err);
    if (rw_len == -1) {
        g_printerr ("%s\n", err->message);
        // TODO
        return;
    }

    guchar *original_hmac = g_malloc (SHA512_DIGEST_SIZE);
    if (!g_seekable_seek (G_SEEKABLE (in_stream), file_size - SHA512_DIGEST_SIZE, G_SEEK_SET, NULL, &err)) {
        g_printerr ("Couldn't set the position, exiting...\n");
        //TODO
        return;
    }
    rw_len = g_input_stream_read (G_INPUT_STREAM (in_stream), original_hmac, SHA512_DIGEST_SIZE, NULL, &err);
    if (rw_len == -1) {
        g_printerr ("%s\n", err->message);
        // TODO
        return;
    }

    if (!g_seekable_seek (G_SEEKABLE (in_stream), 0, G_SEEK_SET, NULL, &err)) {
        g_printerr ("Couldn't set the position, exiting...\n");
        //TODO
        return;
    }
    GFile *file_encrypted_data = get_g_file_with_encrypted_data (in_stream, file_size);
    if (file_encrypted_data == NULL) {
        // TODO
        return;
    }

    if (!setup_keys (pwd, gcry_cipher_get_algo_keylen (header_metadata->algo), header_metadata, decryption_keys)) {
        g_printerr ("Error during key derivation or during memory allocation\n");
        //TODO
        return;
    }

    if (!compare_hmac (decryption_keys->hmac_key, original_hmac, file_encrypted_data)) {
        g_printerr ("HMAC differs from the one stored inside the file.\nEither the password is wrong or the file has been corrupted.\n");
        // TODO
        return;
    }

    decrypt (header_metadata, decryption_keys, file_encrypted_data, file_size - sizeof (Metadata) - SHA512_DIGEST_SIZE, out_stream);

    g_unlink (g_file_get_path (file_encrypted_data));
    // TODO remove encrypted file? Give option to the user

    multiple_unref (5, (gpointer) &file_encrypted_data,
                    (gpointer) &in_stream,
                    (gpointer) &out_stream,
                    (gpointer) &in_file,
                    (gpointer) &out_file);

    multiple_gcry_free (3, (gpointer) &decryption_keys->crypto_key,
                        (gpointer) &decryption_keys->derived_key,
                        (gpointer) &decryption_keys->hmac_key);

    multiple_free (4, (gpointer) &header_metadata,
//.........这里部分代码省略.........
开发者ID:paolostivanin,项目名称:GTKCrypto,代码行数:101,代码来源:decrypt-file.c


示例17: matches

    bool matches(InputStream &stream)
    {
      unsigned char header[12];

      return stream.read(0, header, sizeof header) && decrypt(header);
    }
开发者ID:EQ4,项目名称:qmmp-adplug,代码行数:6,代码来源:magic.cpp


示例18: main

int main()
{
int listen_sock, conn_sock;
int server_len, client_len;
struct sockaddr_in server_address;
struct sockaddr_in client_address;

listen_sock = socket(AF_INET, SOCK_STREAM, 0);
if (listen_sock == -1)
 {
    printf("khong tao duoc socket\n");
    return 0;
 }
 printf("Tao socket thanh cong\n");

server_address.sin_family = AF_INET;
inet_aton("127.0.0.1",&server_address.sin_addr);
server_address.sin_port = htons(5500);
server_len = sizeof(server_address);

if(bind(listen_sock, (struct sockaddr *)&server_address,server_len)<0)
{
	printf("bind failed.\n");
    return 0;
}
printf("bind done\n");
int check = listen(listen_sock,10);
if (check == -1)
 {
 printf("error connect");
 return 0;
 }
printf("waiting connect ...\n");
while(1) {
		client_len = sizeof(client_address);
		conn_sock = accept(listen_sock,(struct sockaddr *)&client_address, &client_len);
		if(conn_sock==-1){
			printf("error connect\n");
			return 1;
		}else{
			printf("Accept new connection\n");
		}
		if(fork() == 0){
			close(listen_sock);

			int sentBytes,revedBytes,i;
			//char buff[1024];
			int chose;
			while(1){
					revedBytes = recv(conn_sock,buff,1024,0);
					if(revedBytes < 0) break;
					if(strcmp(buff,"S")==0) chose = 1;
					else if(strcmp(buff,"M")==0) chose =2;
					else if(strcmp(buff,"exit")==0) chose = 3;									
					switch(chose){
					case 1:
						printf("Menu1 \n");
						while(1){
						    	revedBytes = recv(conn_sock,buff,1024,0);
						        buff[revedBytes]='\0';
						        if(strcmp(buff 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ decrypt_data函数代码示例发布时间:2022-05-30
下一篇:
C++ decrgpulse函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap