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

  • Home
  • SEARCH
  • 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 7696621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:49:23+00:00 2026-05-31T21:49:23+00:00

i’m using that code for encrypt a string with 3DES in IOS and i

  • 0

i’m using that code for encrypt a string with 3DES in IOS and i want decrypt it with php
but it generate a string longer if i use kCCOptionPKCS7Padding ( or shorter if i don’t use it )
when i decrypt it with php it adds more or less chars to de string
how i can fix that ?

that is how i decrypt with php

$key = "f968f8e82961489a8b14b345";
$encrypted = base64_decode($crypt);
$n = mcrypt_module_open(MCRYPT_3DES, null, MCRYPT_MODE_ECB, null);
$fake_iv = str_repeat(chr(0), mcrypt_enc_get_iv_size($n));
mcrypt_generic_init($n, $key, $fake_iv);
$original = mdecrypt_generic($n, $encrypted);

that is where i call function for encrypt

NSString* str= @"test string with random words";
NSData* body =[str dataUsingEncoding:NSUTF8StringEncoding];

NSData *encrypt3DES     = [ViewController TripleDES:body encryptOrDecrypt:kCCEncrypt key:@"f968f8e82961489a8b14b345"];

NSData *encryptBase64   = [GTMBase64 encodeData:encrypt3DES];

that is how i encrypt in ios

+ (NSData*)TripleDES:(NSData*)plainData encryptOrDecrypt:(CCOperation)encryptOrDecrypt key:(NSString*)key {

    const void *vplainText;
    size_t plainTextBufferSize;

    plainTextBufferSize = [plainData length];
    vplainText = (const void *)[plainData bytes];


    CCCryptorStatus ccStatus;
    uint8_t *bufferPtr = NULL;
    size_t bufferPtrSize = 0;
    size_t movedBytes = 0;
    // uint8_t ivkCCBlockSize3DES;

    bufferPtrSize = (plainTextBufferSize + kCCBlockSize3DES) & ~(kCCBlockSize3DES - 1);
    bufferPtr = malloc( bufferPtrSize * sizeof(uint8_t));
    memset((void *)bufferPtr, 0x0, bufferPtrSize);
    // memset((void *) iv, 0x0, (size_t) sizeof(iv));

    //    NSString *key = @"123456789012345678901234";
    NSString *initVec = @"init Vec";
    const void *vkey = (const void *) [key UTF8String];
    const void *vinitVec = (const void *) [initVec UTF8String];

    ccStatus = CCCrypt(encryptOrDecrypt,
                       kCCAlgorithm3DES,
                       (kCCOptionPKCS7Padding | kCCOptionECBMode),
                       vkey, //"123456789012345678901234", //key
                       kCCKeySize3DES,
                       vinitVec, //"init Vec", //iv,
                       vplainText, //"Your Name", //plainText,
                       plainTextBufferSize,
                       (void *)bufferPtr,
                       bufferPtrSize,
                       &movedBytes);
 /*   if (ccStatus == kCCSuccess) NSLog(@"SUCCESS");
    else if (ccStatus == kCCParamError) NSLog( @"PARAM ERROR");
     else if (ccStatus == kCCBufferTooSmall) NSLog( @"BUFFER TOO SMALL");
     else if (ccStatus == kCCMemoryFailure) NSLog( @"MEMORY FAILURE");
     else if (ccStatus == kCCAlignmentError) NSLog( @"ALIGNMENT");
     else if (ccStatus == kCCDecodeError) NSLog( @"DECODE ERROR");
     else if (ccStatus == kCCUnimplemented) NSLog( @"UNIMPLEMENTED");

  */

    NSData *result = [NSData dataWithBytes:(const void *)bufferPtr length:(NSUInteger)movedBytes];

    return result;
}

more info

that is the output i get decrypting with php (at the end of string it add stange square chars)

test string with random words

that is what i want obtaine

test string with random words

that is the Base64 code generated by NSString *base64tring = [[NSString alloc] initWithData:encryptBase64 encoding:NSUTF8StringEncoding];

JuelOxhG5rmLZ32/HNQjxqSPGovPv+lupUz/u0/ryXU=
  • 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-05-31T21:49:24+00:00Added an answer on May 31, 2026 at 9:49 pm

    Without having this tested i guess the reason for your “strange bytes” is the PKCS#5 padding that you add to the string on iOS side. It is not supported by PHPs mcrypt extension, so you would have to remove it yourself. For example, by using a function from the commentary on mcrypt

    function pkcs5_unpad($text)
    {
        $pad = ord($text{strlen($text)-1});
        if ($pad > strlen($text)) return false;
        if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return false;
        return substr($text, 0, -1 * $pad);
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I

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.