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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:43:55+00:00 2026-05-24T03:43:55+00:00

I am encrypting a text string using the following block of code. This code

  • 0

I am encrypting a text string using the following block of code.
This code relates to a method for AES256EncryptWithKey, but when I run the project, and I click on the button that uses this code, I get an uncaught exception and a warning. The warning says: “NSString may not respond to: ‘-AES256EncryptWithKey'”. What can I do? Is it possible to put a chunk of code in that handles exceptions? Or is it something totally different?

NSString *Input  = [Inputbox text];
    [Input AES256encryptWithKey];

Here is the code I have used, that relates to AES256EncryptWithKey:

@implementation NSData (AES256)

- (NSData *)AES256EncryptWithKey:(NSString *)key {
    // 'key' should be 32 bytes for AES256, will be null-padded otherwise
    char keyPtr[kCCKeySizeAES256+1]; // room for terminator (unused)
    bzero(keyPtr, sizeof(keyPtr)); // fill with zeroes (for padding)

    // fetch key data
    [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];

    NSUInteger dataLength = [self length];

    size_t bufferSize = dataLength + kCCBlockSizeAES128;
    void *buffer = malloc(bufferSize);

    size_t numBytesEncrypted = 0;
    CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding,
                                          keyPtr, kCCKeySizeAES256,
                                          NULL /* initialization vector (optional) */,
                                          [self bytes], dataLength, /* input */
                                          buffer, bufferSize, /* output */
                                          &numBytesEncrypted);
    if (cryptStatus == kCCSuccess) {
        //the returned NSData takes ownership of the buffer and will free it on deallocation
        return [NSData dataWithBytesNoCopy:buffer length:numBytesEncrypted];
    }

    free(buffer); //free the buffer;
    return nil;
}

Thank-You in advance. Links, Tutorials, Answers, and anything else is appreciated.

  • 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-24T03:43:56+00:00Added an answer on May 24, 2026 at 3:43 am

    Thats because NSString in fact does not respond to that message – your code adds a category to NSData!

    Remember encryption works on binary data, so you must convert your potentially unicode NSString into a well-defined binary encoding (say, UTF-8)

    The fastest conversion is to use the NSString dataWithEncoding method.

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

Sidebar

Related Questions

I'm using the following code to encrypt files in cocoa: - (NSData *)AES256EncryptWithKey:(NSString *)key
I'm encrypting and then decrypting a string using AES. But my output looks like
This question discusses encrypting data on the iPhone using the crypt() function. As an
I am using Jasypt for encryption. This is my code: public class Encryptor {
I needed some simple string encryption, so I wrote the following code (with a
i found a ruby encryption library which is using this function. def process(text) 0.upto(text.length-1)
Working with OAuth and encrypting the keys with the following function with a string
I'm encrypting and Base64 a string. Everything works great, until I retrieve the encrypted
What is the easiest free method of encrypting my web traffic? I'd like to
What is the difference between encrypting some data vs signing some data (using RSA)?

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.