Objective-C implementation of XXTEA cipher for OS X and iOS.
Open project in Xcode then drag XXTEA
directory (or XXTEA.h
& XXTEA.m
)
to your project directory (or any subdirectory).
Make sure 'Create groups' in 'Added folders' is checked.
#import "XXTEA.h"
// create a random key
unsigned char key[XXTEA_KEY_LENGTH];
XXTEAFillRandomKey(key);
// encrypt sample data
// output: length: 32/36
NSData *data = [@"Hello, world! 你好,世界!" dataUsingEncoding:NSUTF8StringEncoding];
NSData *encrypedData = XXTEAEncryptData(data, key);
NSLog(@"Length: %tu/%tu", data.length, encrypedData.length);
// decrypt data chunk
// output: Hello, world! 你好,世界!
data = XXTEADecryptData(encrypedData, key);
NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
XXTEA is released under the MIT license. See LICENSE for details.