1. #import <Foundation/Foundation.h>
  2. #include <CommonCrypto/CommonCryptor.h>
  3.  
  4. @interface Encryption : NSObject
  5. - (void) Encrypt: (NSString *) _secret;
  6. @end
  7.  
  8. @implementation Encryption
  9. - (void) Encrypt: (NSString *) _secret {
  10. const char mykey[] = { 0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0x41};
  11.         const char mysec[] = { 0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42};
  12.         //NSString *_secret = phrase;
  13.         NSString *bufferPtr;
  14.         size_t movedBytes=0;
  15.  
  16.         CCCryptorStatus ccStatus;
  17.         ccStatus = CCCrypt(encrypt,
  18.         kCCAlgorithmAES128,
  19.         kCCOptionECBMode,
  20.         mykey,
  21.         kCCKeySizeAES256,
  22.         NULL,
  23.         mysec,
  24.         sizeof(_secret),
  25.         (void *)bufferPtr,
  26.         sizeof(bufferPtr),
  27.         &movedBytes
  28. );
  29.  
  30. printf("encrypting %s\n", [ _secret UTF8String ]);
  31. printf("encrypted values are:%s\n", [(NSString*) bufferPtr UTF8String]);
  32. }
  33.  
  34. @end
  35.  
  36. int main(void) {
  37. Encryption *enc = [ [ Encryption alloc ] init ];
  38. [ enc Encrypt: @"Hello, world!" ];
  39. [ enc release ];
  40. return 0;
  41.  
  42. }