Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8989495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:16:26+00:00 2026-06-15T22:16:26+00:00

In the code below, the decrypted text does not match the original plaintext. The

  • 0

In the code below, the decrypted text does not match the original plaintext. The first 12 bytes are messed up. Note that block cipher padding has been disabled. I have tried different values for BUF_SIZE, all multiples of 16 – every time the first 12 bytes of the decrypted data is wrong. Here’s the output:

    plain buf[32]:
    11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11
    11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11
    outlen=32
    outlen=32
    dec buf[32]:
    0C 08 01 46 6D 3D FC E9 98 0A 2D E1 AF A3 95 3A
    0B 31 1B 9D 11 11 11 11 11 11 11 11 11 11 11 11

Here’s the code:

#include <stdio.h>
#include <string.h>
#include <CommonCrypto/CommonCryptor.h>

static void
dumpbuf(const char* label, const unsigned char* pkt, unsigned int len)
{
    const int bytesPerLine = 16;

    if (label) {
        printf("%s[%d]:\n", label, len);
    }

    for (int i = 0; i < int(len); i++) {
        if (i && ((i % bytesPerLine) == 0)) {
            printf("\n");
        }
        unsigned int c = (unsigned int)pkt[i] & 0xFFu;
        printf("%02X ", c);
    }
    printf("\n");
}

int main(int argc, char* argv[])
{
    unsigned char key[16];
    unsigned char iv[16];

    memset(key, 0x22, sizeof(key));
    memset(iv, 0x33, sizeof(iv));

#define BUF_SIZE  32
    unsigned char plainBuf[BUF_SIZE];
    unsigned char encBuf[BUF_SIZE];
    memset(plainBuf, 0x11, sizeof(plainBuf));
    dumpbuf("plain buf", plainBuf, sizeof(plainBuf));

    int outlen;
    CCCryptorStatus status;
    status = CCCrypt(kCCEncrypt, kCCAlgorithmAES128, 0,
            key, kCCKeySizeAES128, iv, plainBuf, sizeof(plainBuf),
            encBuf, sizeof(encBuf), (size_t*)&outlen);
    if (kCCSuccess != status) {
        fprintf(stderr, "FEcipher: CCCrypt failure\n");
        return -1;
    }
    printf("outlen=%d\n", outlen);

    status = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, 0,
            key, kCCKeySizeAES128, iv, encBuf, sizeof(encBuf),
            plainBuf, sizeof(plainBuf), (size_t*)&outlen);
    if (kCCSuccess != status) {
        fprintf(stderr, "FEcipher: CCCrypt failure\n");
        return -1;
    }
    printf("outlen=%d\n", outlen);
    dumpbuf("dec buf", plainBuf, sizeof(plainBuf));
    return 0;
}

Thanks,
Hari

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:16:27+00:00Added an answer on June 15, 2026 at 10:16 pm

    @owlstead, thanks for your response. CBC is the default – you don’t need to specify anything special in the options to enable it.

    The same code using CCCrypt() was working before. I don’t know what changed – may be a new library was installed during an update. Instead of using the convenience function CCCrypt() I’m now using the Create/Update/Final API – it works, so I have a workaround.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

below code sample does not return the original text after encrypt/decrypt operation and I
The code block that i use is below: SELECT * FROM crypted_tbl WHERE Username=AES_ENCRYPT('aydu',
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
The code below simply didn't work. document.getElementById('files').addEventListener('change', handleFileSelect, false); reported by firebug that this
Code below contains a JS function that receives as parameter String €€ (Euro sign).
Code below. The outcome of this is that each document ends up with the
First, I have only written the code below for academic purposes. The reason I
Given below is the code(not complete yet) I have written to encrypt and decrypt
I have a some code below. My problem that i have a strange ending
Code below, not sure what i'm doing wrong. It is an employee database. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.