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 7782917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:41:23+00:00 2026-06-01T19:41:23+00:00

Recently, I am using CCCrypt to implement some self defined crypto algorithm. However, when

  • 0

Recently, I am using CCCrypt to implement some self defined crypto algorithm. However, when i use CCCryptorUpdate to decrypt cipher text, the output is always 8 bytes less than origin plain text. Following is my codes:

+ (void) EncryptBy3DES:(NSInputStream*)strmSrc Output:(NSOutputStream*)strmDest CryptoRef:(CCCryptorRef)tdesCrypto
{   
    size_t  dataOutMoved;
    uint8_t inputBuf[BlockSize];
    uint8_t outputBuf[BlockSize];

    CCCryptorStatus cryptStatus;
    int iBytesRead = 0;

    while ( (iBytesRead = [strmSrc read:inputBuf maxLength:BlockSize]) > 0 ) 
    {
        NSLog(@"Bytes read from plain buffer: %d", iBytesRead);
        [Util FillBuffer:inputBuf Length:BlockSize Current:iBytesRead];

        cryptStatus = CCCryptorUpdate(tdesCrypto, &inputBuf, BlockSize, &outputBuf, BlockSize, &dataOutMoved);
        assert(dataOutMoved<=BlockSize && cryptStatus==noErr);
        NSLog(@"EncDataOutMoved: %ld", dataOutMoved);
        [Util FillBuffer:outputBuf Length:BlockSize Current:dataOutMoved];
        [strmDest write:outputBuf maxLength:BlockSize];
    }
}

+ (void) DecryptBy3DES:(NSInputStream*)strmSrc Output:(NSOutputStream*)strmDest CryptoRef:(CCCryptorRef)tdesCrypto
{       
    size_t  dataOutMoved;
    uint8_t inputBuf[BlockSize];
    uint8_t outputBuf[BlockSize+kCCBlockSize3DES];

    CCCryptorStatus cryptStatus;
    int iBytesRead = 0;

    while ( (iBytesRead = [strmSrc read:inputBuf maxLength:BlockSize]) > 0 ) 
    {
        NSLog(@"Bytes read from cipher buffer: %d", iBytesRead);
        cryptStatus = CCCryptorUpdate(tdesCrypto, &inputBuf, BlockSize, &outputBuf, BlockSize+kCCBlockSize3DES, &dataOutMoved);
        NSLog(@"Lengh needed: %zu", CCCryptorGetOutputLength(tdesCrypto, BlockSize, YES));
        NSLog(@"DecDataOutMoved: %ld", dataOutMoved);
        assert(dataOutMoved<=BlockSize && cryptStatus==noErr);
        [strmDest write:outputBuf maxLength:dataOutMoved];
    }
}


I encrypted 3 buffer of 4096. When decrypting them, the log shows that the size of 1st decrypted data is 4088, BUT! The missing data is actually in the begining of the 2nd decrypted data. 

2012-04-14 15:17:41.929 otest[25168:7803] Bytes read from cipher buffer: 4096
2012-04-14 15:17:41.929 otest[25168:7803] Lengh needed: 4104
2012-04-14 15:17:41.930 otest[25168:7803] DecDataOutMoved: 4088
end of 1st block:<..d71eaf27 affc4c8c b1c54afa c5434397 ebc17a49>

2012-04-14 15:17:45.291 otest[25168:7803] Bytes read from cipher buffer: 4096
2012-04-14 15:17:45.292 otest[25168:7803] Lengh needed: 4104
2012-04-14 15:17:45.293 otest[25168:7803] DecDataOutMoved: 4096
begining of 2nd block <**86b61bce b4342728** 88240a64 837327d4 0bb572a2 f5220928

Note that 86b61bce b4342728 was in the end of 1st block before encryption.

I also checked the begining of the 1st block, and I am sure that I did not mess up with the range of data. It seems that the data are decrypted, but they are not retrieved until the next operation.

I want to get a full block at each encrypt/decrypt operation, but I don’t want to use function CCCrypt since I have to pass both Key and Iv bits to it. I just want to pass CCCryptorRef to it, which is relatively simple.

Hubert

  • 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-01T19:41:24+00:00Added an answer on June 1, 2026 at 7:41 pm

    You need to finish the encryption and decryption by calling CCCryptFinal. This will take care of adding/removing padding.

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

Sidebar

Related Questions

Was recently using some code along the lines of $(#divMenuContainer:visible).hide(explode); However after some time
I recently started using Masterpages, the thing is I would like to add text
I recently started using Eclipse for PHP Development. Please suggest me some HTML WYSIWYG
I was recently using .net reflector to look at some DLL files, and I
I recently began using BIRT and have developed a report to use with my
I recently started using Git as my version control system for some Cocoa projects
I recently started using Jira with the GreenHopper plugin. However, I don't feel like
I was recently using a commercial centrally controlled version control system in a large
I recently started using lcov to visualize my code coverage. It's a great tool.
Ive recently started using CodeIgniter as I was searching for a very lightweight framework

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.