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.
We create a string sampleString
to demonstrate how to use xxtea.
xxtea works with NSData
so,
NSString *sampleString = @"Hello, world! 你好,世界!";
NSData *data = [sampleString dataUsingEncoding:NSUTF8StringEncoding];
#import "XXTEA.h"
Load your secret key (16-bytes memory block) into memory or generate a random one:
char key[XXTEA_KEY_LENGTH];
XXTEAFillRandomKey(key);
NSData *encryptedData = XXTEAEncryptData(data, key);
// output: length: 32/36
NSLog(@"Length: %tu/%tu", data.length, encryptedData.length);
NSData *originalData = XXTEADecryptData(encryptedData, key);
// output: Hello, world! 你好,世界!
NSString *originalString = [NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@", originalString);
XXTEA is released under the MIT license. See LICENSE for details.