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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:58:04+00:00 2026-06-17T06:58:04+00:00

i have a problem: I encrypt data, and encode it in base64..after, i send

  • 0

i have a problem:

I encrypt data, and encode it in base64..after, i send it to my page php and it decode and decrypt data. OK!

Now, if i encrypt and encode data in php and send it to my application, my app decode data and decrypt data, but the result is half of length of string. Look this:

PLAINTEXT: xLxE9sY8vkBTGDpvz0DkLkejLSjuVhBq

CHIPER FROM SERVER: jp6gtdy/tf8mnQoeZCQjPuauq089eJvmns0DP4kvDzw=

DECRYPT CHIPER SERVER IN MY APP: xLxE9sY8vkBTGDpv <— IT’S HALF!!!!

But if i encrypt the plaintext in my app, the result is different:

CHIPER FROM APP: jp6gtdy/tf8mnQoeZCQjPuauq089eJvmns0DP4kvDzzjd4QC2afnXreH/VpUo/Mw

CHIPER FROM SERVER: jp6gtdy/tf8mnQoeZCQjPuauq089eJvmns0DP4kvDzw=

and decrypt is ok:

DECRYPT CHIPER APP: xLxE9sY8vkBTGDpvz0DkLkejLSjuVhBq

Now, i have used a online tool with the 2 chyper text..and the result is the same!! the plaintext!!! TRY!!! (http://www.tools4noobs.com/online_tools/decrypt/) !?!?!?!

My function in my app is this:

+ (NSData*)decryptData:(NSData*)data key:(NSData*)key iv:(NSData*)iv;
{
    NSData* result = nil;

    // setup key
    unsigned char cKey[FBENCRYPT_KEY_SIZE];
    bzero(cKey, sizeof(cKey));
    [key getBytes:cKey length:FBENCRYPT_KEY_SIZE];

    // setup iv
    char cIv[FBENCRYPT_BLOCK_SIZE];
    bzero(cIv, FBENCRYPT_BLOCK_SIZE);
    if (iv) {
        [iv getBytes:cIv length:FBENCRYPT_BLOCK_SIZE];
    }

    // setup output buffer
    size_t bufferSize = [data length] + FBENCRYPT_BLOCK_SIZE;
    void *buffer = malloc(bufferSize);

    // do decrypt
    size_t decryptedSize = 0;
    CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt,
                                          FBENCRYPT_ALGORITHM,
                                          kCCOptionPKCS7Padding,
                                          cKey,
                                          FBENCRYPT_KEY_SIZE,
                                          cIv,
                                          [data bytes],
                                          [data length],
                                          buffer,
                                          bufferSize,
                                          &decryptedSize);

    if (cryptStatus == kCCSuccess) {
        result = [NSData dataWithBytesNoCopy:buffer length:decryptedSize];
    } else {
        free(buffer);
        NSLog(@"[ERROR] failed to decrypt| CCCryptoStatus: %d", cryptStatus);
    }

    return result;
}

This function first decode and after decrypt:

  + (NSString*)decryptBase64String:(NSString*)encryptedBase64String keyString:(NSString*)keyString
    {
        NSData* encryptedData = [NSData dataFromBase64String:encryptedBase64String];
        NSData* data = [self decryptData:encryptedData
                                     key:[keyString dataUsingEncoding:NSUTF8StringEncoding]
                                      iv:nil];
        if (data) {
            return [[[NSString alloc] initWithData:data
                                          encoding:NSUTF8StringEncoding] autorelease];
        } else {
            return nil;
        }
    }

Decode function:

+ (NSData *)dataFromBase64String:(NSString *)aString
{
    NSData *data = [aString dataUsingEncoding:NSASCIIStringEncoding];
    size_t outputLength;
    void *outputBuffer = NewBase64Decode([data bytes], [data length], &outputLength);
    NSData *result = [NSData dataWithBytes:outputBuffer length:outputLength];
    free(outputBuffer);
    return result;
}

void *NewBase64Decode(
    const char *inputBuffer,
    size_t length,
    size_t *outputLength)
{
    if (length == -1)
    {
        length = strlen(inputBuffer);
    }

    size_t outputBufferSize =
        ((length+BASE64_UNIT_SIZE-1) / BASE64_UNIT_SIZE) * BINARY_UNIT_SIZE;
    unsigned char *outputBuffer = (unsigned char *)malloc(outputBufferSize);

    size_t i = 0;
    size_t j = 0;
    while (i < length)
    {
        //
        // Accumulate 4 valid characters (ignore everything else)
        //
        unsigned char accumulated[BASE64_UNIT_SIZE];
        size_t accumulateIndex = 0;
        while (i < length)
        {
            unsigned char decode = base64DecodeLookup[inputBuffer[i++]];
            if (decode != xx)
            {
                accumulated[accumulateIndex] = decode;
                accumulateIndex++;

                if (accumulateIndex == BASE64_UNIT_SIZE)
                {
                    break;
                }
            }
        }

        //
        // Store the 6 bits from each of the 4 characters as 3 bytes
        //
        // (Uses improved bounds checking suggested by Alexandre Colucci)
        //
        if(accumulateIndex >= 2)  
            outputBuffer[j] = (accumulated[0] << 2) | (accumulated[1] >> 4);  
        if(accumulateIndex >= 3)  
            outputBuffer[j + 1] = (accumulated[1] << 4) | (accumulated[2] >> 2);  
        if(accumulateIndex >= 4)  
            outputBuffer[j + 2] = (accumulated[2] << 6) | accumulated[3];
        j += accumulateIndex - 1;
    }

    if (outputLength)
    {
        *outputLength = j;
    }
    return outputBuffer;
}
  • 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-17T06:58:05+00:00Added an answer on June 17, 2026 at 6:58 am

    The string is 32 bytes in length, this is two blocks in size. The Base64 is also 32 bytes in length so no padding was added, there is no space for padding so it is not PKCS7 padded, remove the kCCOptionPKCS7Padding option.

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

Sidebar

Related Questions

I have the problem that I am trying to send data as a base64
I encrypt/decrypt a message like the following: Encrypt string -> base64 encode bytes ->
I am trying to encrypt and decrypt the data with RSA 2048. We have
I have a problem (server side) when i encrypt data from a client and
I'm using this code snippet to encrypt/decrypt data in my app's database: http://www.androidsnippets.com/encryptdecrypt-strings It
I have a problem with ecrypting data using AES-128/ecb/PKCS5Padding+base64. I am using the following
I have problem in below code. I have created two methods ENCRYPT and DECRYPT
I'm using gnupg to encrypt and decrypt data via powershell script and the problem
I have problem with repopulating form_upload after validation. Other input fields or selectboxes are
I have problem with show or hide form in Window Form Application. I start

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.