login about faq

We purchased a developer license for ChilKat and we're using it in an iOS app. We frequently have to encrypt large files that are first opened for viewing in memory.

If a file has 24 MB, when we encrypt it using

CkoCrypt2* encryptCrypt = [self newCkoCrypt2];

// Set the key. [encryptCrypt SetEncodedKey:key encoding: @"base64"];

// Set the IV [encryptCrypt SetEncodedIV:iv encoding: @"base64"];

NSFileHandle* file = [NSFileHandle fileHandleForWritingAtPath:toPath]; [file writeData:[encryptCrypt EncryptBytes:data]];

we end up using 24 + 24 x 2 = 24 + 48 MB.. which is a lot of memory for an iPad 1.

It would be very nice to encrypt from memory (NSData) to a file (Path) and this way we would only use memory for the crypto's buffer and the original data.

Can we somehow achieve this?

asked Dec 06 '12 at 14:38

chilkat's gravatar image

chilkat ♦♦
11.8k316358421


I checked the memory usage for the C++ case, and if 24MB is encrypted, then the max memory usage is 48MB. The Chilkat Objective-C implementation is a thin wrapper around the C++ libs. Here's what the EncryptBytes wrapping looks like:

// method: EncryptBytes
- (NSData *)EncryptBytes: (NSData *)bData
{
    CkByteData arg1;
    arg1.append2([bData bytes],[bData length]);
    CkByteData bd;
    bool b = ((CkCrypt2 *)m_obj)->EncryptBytes(arg1,bd);
    if (!b) return nil;
    return [NSData dataWithBytes:bd.getData() length:bd.getSize()];
}

I don't know of anything that can be done to reduce the amount of memory. One option might be to use the Chilkat C++ libs for iOS in your app to avoid the extra copy to NSData. The CkByteData object has a method for saving the contents directly to a file.

link

answered Dec 06 '12 at 14:46

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

edited Dec 06 '12 at 14:46

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×94
×1

Asked: Dec 06 '12 at 14:38

Seen: 895 times

Last updated: Dec 06 '12 at 14:46

powered by OSQA