这篇教程C++ AES_cbc_encrypt函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中AES_cbc_encrypt函数的典型用法代码示例。如果您正苦于以下问题:C++ AES_cbc_encrypt函数的具体用法?C++ AES_cbc_encrypt怎么用?C++ AES_cbc_encrypt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了AES_cbc_encrypt函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: whileuint8_t *aos_cipher_decrypt(struct aos_encryption *enc, const uint8_t *in, unsigned int length){ uint8_t *decrypted; unsigned int done = 0; decrypted = (uint8_t *)malloc(length); if(!decrypted) return NULL; while(done < length) { uint8_t iv[AES_BLOCK_SIZE]; uint8_t data[AES_BLOCK_SIZE]; struct aos_block *block = (struct aos_block *)&data; memcpy(iv, enc->iv, AES_BLOCK_SIZE); AES_cbc_encrypt(&in[done], data, AES_BLOCK_SIZE, &enc->key, iv, AES_DECRYPT); memcpy(&decrypted[done], &data, AES_BLOCK_SIZE); done += AES_BLOCK_SIZE; AES_cbc_encrypt(&in[done], &decrypted[done], block->length-AES_BLOCK_SIZE, &enc->key, iv, AES_DECRYPT); done += block->length-AES_BLOCK_SIZE; } return decrypted;}
开发者ID:kenrestivo,项目名称:aos-tools,代码行数:26,
示例2: blockchain_decryptstatic int blockchain_decrypt(unsigned char *derived_key, unsigned char *data){ unsigned char out[SAFETY_FACTOR]; AES_KEY akey; unsigned char iv[16]; memcpy(iv, cur_salt->data, 16); if(AES_set_decrypt_key(derived_key, 256, &akey) < 0) { fprintf(stderr, "AES_set_decrypt_key failed in crypt!/n"); } AES_cbc_encrypt(data + 16, out, 16, &akey, iv, AES_DECRYPT); /* various tests */ if (out[0] != '{') // fast test return -1; // "guid" will be found in the first block if (memmem(out, 16, "/"guid/"", 6)) { memcpy(iv, cur_salt->data, 16); //IV has to be reset. AES_cbc_encrypt(data + 16, out, SAFETY_FACTOR, &akey, iv, AES_DECRYPT); if (memmem(out, SAFETY_FACTOR, "/"sharedKey/"", 11) && memmem(out, SAFETY_FACTOR, "/"options/"", 9)) // Note, we 'could' check that the guid and sharedKey values are // 'valid' GUID's, but there really is no point. We already have // 2^216 confidence in the simple text strings being found. return 0; } return -1;}
开发者ID:Allen-smith,项目名称:ctf-tools,代码行数:28,
示例3: aes_encryptint aes_encrypt(void *in, size_t len, unsigned char **out, unsigned char *iv, unsigned char *key){ AES_KEY aeskey; int ret; if (!len) return 0; ret = AES_set_encrypt_key(key, 256, &aeskey); assert(!ret); printf("(len: %ld pad: %ld)/n", len, len % 16); len += len % 16; *out = calloc(1, len); // consider padding.. assert(*out);#ifdef SKIP_LAST_WORD AES_cbc_encrypt(in, *out, len-4, &aeskey, iv, AES_ENCRYPT); memcpy(*out + (len - 4), in + (len - 4), 4);#else AES_cbc_encrypt(in, *out, len, &aeskey, iv, AES_ENCRYPT); #endif printf("/nplaintext (excerpt):/n"); print_hex(in, 128, 0); printf("ciphertext (excerpt):/n"); print_hex(*out, 128, 0); return 0;}
开发者ID:YtnbFirewings,项目名称:kcache,代码行数:32,
示例4: main// main entrypointint main(int argc, char **argv){ int keylength; printf("Give a key length [only 128 or 192 or 256!]:/n"); scanf("%d", &keylength); /* generate a key with a given length */ unsigned char aes_key[keylength/8]; memset(aes_key, 0, keylength/8); if (!RAND_bytes(aes_key, keylength/8)) exit(-1); /* input struct creation */ size_t inputslength = sizeof(USR_TICKET); USR_TICKET ticket; ticket.ticketId = 1; time_t now = time(NULL); strftime(ticket.date, 20, "%Y-%m-%d", localtime(&now)); strcpy(ticket.username, "Hello AES"); printf("Username - %s/n", ticket.username); printf("Ticket Id - %d/n", ticket.ticketId); printf("Date - %s/n", ticket.date); /* init vector */ unsigned char iv_enc[AES_BLOCK_SIZE], iv_dec[AES_BLOCK_SIZE]; RAND_bytes(iv_enc, AES_BLOCK_SIZE); memcpy(iv_dec, iv_enc, AES_BLOCK_SIZE); // buffers for encryption and decryption const size_t encslength = ((inputslength + AES_BLOCK_SIZE) / AES_BLOCK_SIZE) * AES_BLOCK_SIZE; unsigned char enc_out[encslength]; unsigned char dec_out[inputslength]; memset(enc_out, 0, sizeof(enc_out)); memset(dec_out, 0, sizeof(dec_out)); // so i can do with this aes-cbc-128 aes-cbc-192 aes-cbc-256 AES_KEY enc_key, dec_key; AES_set_encrypt_key(aes_key, keylength, &enc_key); AES_cbc_encrypt((unsigned char *)&ticket, enc_out, encslength, &enc_key, iv_enc, AES_ENCRYPT); AES_set_decrypt_key(aes_key, keylength, &dec_key); AES_cbc_encrypt(enc_out, dec_out, encslength, &dec_key, iv_dec, AES_DECRYPT); printf("original:/t"); hex_print((unsigned char *)&ticket, inputslength); printf("encrypt:/t"); hex_print(enc_out, sizeof(enc_out)); printf("decrypt:/t"); hex_print(dec_out, sizeof(dec_out)); USR_TICKET * dyc = (USR_TICKET *)dec_out; printf("Username - %s/n", dyc->username); printf("Ticket Id - %d/n", dyc->ticketId); printf("Date - %s/n", dyc->date); return 0;}
开发者ID:HaykGrig,项目名称:My-C-Projects,代码行数:60,
示例5: akcdecryptstatic int akcdecrypt(unsigned char *derived_key, unsigned char *data){ unsigned char out[CTLEN]; int pad, n, i, key_size; AES_KEY akey; unsigned char iv[16]; memcpy(iv, data + CTLEN - 32, 16); if(AES_set_decrypt_key(derived_key, 128, &akey) < 0) { fprintf(stderr, "AES_set_decrypt_key failed in crypt!/n"); } AES_cbc_encrypt(data + CTLEN - 16, out + CTLEN - 16, 16, &akey, iv, AES_DECRYPT); // now check padding pad = out[CTLEN - 1]; if(pad < 1 || pad > 16) /* AES block size is 128 bits = 16 bytes */ // "Bad padding byte. You probably have a wrong password" return -1; n = CTLEN - pad; key_size = n / 8; if(key_size != 128 && key_size != 192 && key_size != 256) // "invalid key size" return -1; for(i = n; i < CTLEN; i++) if(out[i] != pad) // "Bad padding. You probably have a wrong password" return -1; return 0;}
开发者ID:Allen-smith,项目名称:ctf-tools,代码行数:29,
|