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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:54:12+00:00 2026-05-28T02:54:12+00:00

Here is my code: -(IBAction)encryptText:(id)sender { key = self.tvKey.text; CCCryptorStatus status = kCCSuccess; algorithm

  • 0

Here is my code:

-(IBAction)encryptText:(id)sender
{
key = self.tvKey.text;

CCCryptorStatus status = kCCSuccess;                                        
algorithm = kCCAlgorithmAES128;                                                
CCOptions opts = kCCOptionPKCS7Padding;

NSData *keyData = [key dataUsingEncoding:NSUTF8StringEncoding];

NSString *plainString = [NSString stringWithFormat:@"%@", self.tvEntryText.text];
NSData *plainData = [plainString dataUsingEncoding:NSUTF8StringEncoding];

NSData *encryptedData = [plainData dataEncryptedUsingAlgorithm: algorithm     
                                                           key: keyData       
                                          initializationVector: nil             
                                                       options: opts           
                                                         error: &status];    


if ( status != kCCSuccess ) {
    NSError * err = [NSError errorWithCCCryptorStatus: status];
    self.lblKeyMsg.text = [NSString stringWithFormat:@"Encryption failed: %s", [[err localizedDescription] UTF8String]];
    self.lblKeyMsg.textColor = [UIColor redColor];
    return;
}

NSString *encryptedString = [[[NSString alloc] initWithData:encryptedData encoding:NSUTF8StringEncoding] autorelease];
self.tvResultText.text = encryptedString;

}

The second to last statement I am converting the encrypted NSData to an NSString for display purposes, but it comes back nil. Nil is a valid response indicating and error. I have stopped the execution right after that statement has run and here are the vaues:

(gdb) po keyData
<61616161 61616161 61617373 73737373 73737373 64646464 64646464 64646666>
(gdb) po key
aaaaaaaaaassssssssssddddddddddff
(gdb) po plainString
this is a test.
(gdb) po plainData
<74686973 20697320 61207465 73742e>
(gdb) po encryptedData
<f7074146 b295e340 0d947d53 9ea629cf>
(gdb) po encryptedString
Can't print the description of a NIL object.
(gdb) po status
Can't print the description of a NIL object.
(gdb) 

The status is nil indicating that there was NO error in the encryption. All values appear to be as expected, but the initWithData fails. Here is the operations iPhone view:

The app screen when Encrypt button is pressed

Why is the initWithData failing here ?

  • 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-28T02:54:13+00:00Added an answer on May 28, 2026 at 2:54 am

    As the documentation says, initWithData:encoding: may return nil if the data passed is not valid data for the encoding. Unlike some encodings, you can’t just take arbitrary data and pretend it’s UTF8 data – it has to conform to the UTF8 specification.

    Your encryptedData NSData object will contain seemingly random data – highly unlikely to be valid utf8 data and so initWithData:encoding: is very likely to fail.

    If you’re just looking for something that you can stick in a text box, you might want to try base64 encoding the encrypted data.

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

Sidebar

Related Questions

Here's the code: - (IBAction) charlieInputText:(id)sender { //getting value from text field when entered
Here is the code: -(IBAction)customButtonPressed:(id)sender { NSString *text = Field.text; //label is called Label
Here is the code: - (IBAction) charlieImputText:(id)sender { NSAppleScript *keystrokeReturn = [[NSAppleScript alloc] initWithSource:@tell
Here is the code: - (IBAction) startRecognition:(id)sender { backgroundSoundLevel = [backgroundSoundChange stringValue]; timer =
Here's my code: - (IBAction)showTaskDetailView:(id)sender { [window setContentView:viewTaskView]; } How would I fade out
enter code here-(IBAction)Call:(id)sender{ //[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@tel://18005551234]]; /*NSString *phoneStr = [[NSString alloc] initWithFormat:@tel:%@,phoneNumber.text]; NSURL
Here is the code: - (IBAction)textFieldDidBeginEditing:(UITextField *)textField { NSLog(@Inside textfieldDidBeginEditing); textFieldBeingEdited = textField; }
I have this code: - (IBAction)next { // <-- here index++; // Set imageCount
I have the following code: - (IBAction)showDirectMessage:(id)sender { DetailMessageViewController * dmvc = [[DetailMessageViewController alloc]
I'm dealing here with a new problem. I started with the following code: -(IBAction)

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.