Commits

James Sumners committed 6e0c592 Draft

Initial commit.

Comments (0)

Files changed (6)

+syntax: glob
+*.xcworkspacedata
+*.xcuserstate
+*/xcuserdata/*

JBSCrypto.xcodeproj/project.pbxproj

+// !$*UTF8*$!
+{
+	archiveVersion = 1;
+	classes = {
+	};
+	objectVersion = 46;
+	objects = {
+
+/* Begin PBXBuildFile section */
+		117183781618FCD500AB9F6D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 117183771618FCD500AB9F6D /* Foundation.framework */; };
+		1171837B1618FCD500AB9F6D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 1171837A1618FCD500AB9F6D /* main.m */; };
+		117183871618FD0A00AB9F6D /* JBSCrypto.m in Sources */ = {isa = PBXBuildFile; fileRef = 117183861618FD0A00AB9F6D /* JBSCrypto.m */; };
+		117183891618FEC500AB9F6D /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 117183881618FEC500AB9F6D /* Security.framework */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXCopyFilesBuildPhase section */
+		117183711618FCD500AB9F6D /* CopyFiles */ = {
+			isa = PBXCopyFilesBuildPhase;
+			buildActionMask = 2147483647;
+			dstPath = /usr/share/man/man1/;
+			dstSubfolderSpec = 0;
+			files = (
+			);
+			runOnlyForDeploymentPostprocessing = 1;
+		};
+/* End PBXCopyFilesBuildPhase section */
+
+/* Begin PBXFileReference section */
+		117183731618FCD500AB9F6D /* JBSCrypto */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = JBSCrypto; sourceTree = BUILT_PRODUCTS_DIR; };
+		117183771618FCD500AB9F6D /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+		1171837A1618FCD500AB9F6D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+		1171837D1618FCD500AB9F6D /* JBSCrypto-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "JBSCrypto-Prefix.pch"; sourceTree = "<group>"; };
+		117183851618FD0A00AB9F6D /* JBSCrypto.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JBSCrypto.h; sourceTree = "<group>"; };
+		117183861618FD0A00AB9F6D /* JBSCrypto.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JBSCrypto.m; sourceTree = "<group>"; };
+		117183881618FEC500AB9F6D /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+		117183701618FCD500AB9F6D /* Frameworks */ = {
+			isa = PBXFrameworksBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				117183891618FEC500AB9F6D /* Security.framework in Frameworks */,
+				117183781618FCD500AB9F6D /* Foundation.framework in Frameworks */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+		117183681618FCD500AB9F6D = {
+			isa = PBXGroup;
+			children = (
+				117183791618FCD500AB9F6D /* JBSCrypto */,
+				117183761618FCD500AB9F6D /* Frameworks */,
+				117183741618FCD500AB9F6D /* Products */,
+			);
+			sourceTree = "<group>";
+		};
+		117183741618FCD500AB9F6D /* Products */ = {
+			isa = PBXGroup;
+			children = (
+				117183731618FCD500AB9F6D /* JBSCrypto */,
+			);
+			name = Products;
+			sourceTree = "<group>";
+		};
+		117183761618FCD500AB9F6D /* Frameworks */ = {
+			isa = PBXGroup;
+			children = (
+				117183881618FEC500AB9F6D /* Security.framework */,
+				117183771618FCD500AB9F6D /* Foundation.framework */,
+			);
+			name = Frameworks;
+			sourceTree = "<group>";
+		};
+		117183791618FCD500AB9F6D /* JBSCrypto */ = {
+			isa = PBXGroup;
+			children = (
+				1171837A1618FCD500AB9F6D /* main.m */,
+				1171837C1618FCD500AB9F6D /* Supporting Files */,
+				117183851618FD0A00AB9F6D /* JBSCrypto.h */,
+				117183861618FD0A00AB9F6D /* JBSCrypto.m */,
+			);
+			path = JBSCrypto;
+			sourceTree = "<group>";
+		};
+		1171837C1618FCD500AB9F6D /* Supporting Files */ = {
+			isa = PBXGroup;
+			children = (
+				1171837D1618FCD500AB9F6D /* JBSCrypto-Prefix.pch */,
+			);
+			name = "Supporting Files";
+			sourceTree = "<group>";
+		};
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+		117183721618FCD500AB9F6D /* JBSCrypto */ = {
+			isa = PBXNativeTarget;
+			buildConfigurationList = 117183821618FCD500AB9F6D /* Build configuration list for PBXNativeTarget "JBSCrypto" */;
+			buildPhases = (
+				1171836F1618FCD500AB9F6D /* Sources */,
+				117183701618FCD500AB9F6D /* Frameworks */,
+				117183711618FCD500AB9F6D /* CopyFiles */,
+			);
+			buildRules = (
+			);
+			dependencies = (
+			);
+			name = JBSCrypto;
+			productName = JBSCrypto;
+			productReference = 117183731618FCD500AB9F6D /* JBSCrypto */;
+			productType = "com.apple.product-type.tool";
+		};
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+		1171836A1618FCD500AB9F6D /* Project object */ = {
+			isa = PBXProject;
+			attributes = {
+				LastUpgradeCheck = 0430;
+			};
+			buildConfigurationList = 1171836D1618FCD500AB9F6D /* Build configuration list for PBXProject "JBSCrypto" */;
+			compatibilityVersion = "Xcode 3.2";
+			developmentRegion = English;
+			hasScannedForEncodings = 0;
+			knownRegions = (
+				en,
+			);
+			mainGroup = 117183681618FCD500AB9F6D;
+			productRefGroup = 117183741618FCD500AB9F6D /* Products */;
+			projectDirPath = "";
+			projectRoot = "";
+			targets = (
+				117183721618FCD500AB9F6D /* JBSCrypto */,
+			);
+		};
+/* End PBXProject section */
+
+/* Begin PBXSourcesBuildPhase section */
+		1171836F1618FCD500AB9F6D /* Sources */ = {
+			isa = PBXSourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				1171837B1618FCD500AB9F6D /* main.m in Sources */,
+				117183871618FD0A00AB9F6D /* JBSCrypto.m in Sources */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
+/* End PBXSourcesBuildPhase section */
+
+/* Begin XCBuildConfiguration section */
+		117183801618FCD500AB9F6D /* Debug */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				ALWAYS_SEARCH_USER_PATHS = NO;
+				ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+				COPY_PHASE_STRIP = NO;
+				GCC_C_LANGUAGE_STANDARD = gnu99;
+				GCC_DYNAMIC_NO_PIC = NO;
+				GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+				GCC_OPTIMIZATION_LEVEL = 0;
+				GCC_PREPROCESSOR_DEFINITIONS = (
+					"DEBUG=1",
+					"$(inherited)",
+				);
+				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+				GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+				GCC_WARN_ABOUT_RETURN_TYPE = YES;
+				GCC_WARN_UNINITIALIZED_AUTOS = YES;
+				GCC_WARN_UNUSED_VARIABLE = YES;
+				MACOSX_DEPLOYMENT_TARGET = 10.7;
+				ONLY_ACTIVE_ARCH = YES;
+				SDKROOT = macosx;
+			};
+			name = Debug;
+		};
+		117183811618FCD500AB9F6D /* Release */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				ALWAYS_SEARCH_USER_PATHS = NO;
+				ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+				COPY_PHASE_STRIP = YES;
+				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+				GCC_C_LANGUAGE_STANDARD = gnu99;
+				GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+				GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+				GCC_WARN_ABOUT_RETURN_TYPE = YES;
+				GCC_WARN_UNINITIALIZED_AUTOS = YES;
+				GCC_WARN_UNUSED_VARIABLE = YES;
+				MACOSX_DEPLOYMENT_TARGET = 10.7;
+				SDKROOT = macosx;
+			};
+			name = Release;
+		};
+		117183831618FCD500AB9F6D /* Debug */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				GCC_PRECOMPILE_PREFIX_HEADER = YES;
+				GCC_PREFIX_HEADER = "JBSCrypto/JBSCrypto-Prefix.pch";
+				PRODUCT_NAME = "$(TARGET_NAME)";
+			};
+			name = Debug;
+		};
+		117183841618FCD500AB9F6D /* Release */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				GCC_PRECOMPILE_PREFIX_HEADER = YES;
+				GCC_PREFIX_HEADER = "JBSCrypto/JBSCrypto-Prefix.pch";
+				PRODUCT_NAME = "$(TARGET_NAME)";
+			};
+			name = Release;
+		};
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+		1171836D1618FCD500AB9F6D /* Build configuration list for PBXProject "JBSCrypto" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				117183801618FCD500AB9F6D /* Debug */,
+				117183811618FCD500AB9F6D /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
+		};
+		117183821618FCD500AB9F6D /* Build configuration list for PBXNativeTarget "JBSCrypto" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				117183831618FCD500AB9F6D /* Debug */,
+				117183841618FCD500AB9F6D /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
+		};
+/* End XCConfigurationList section */
+	};
+	rootObject = 1171836A1618FCD500AB9F6D /* Project object */;
+}

JBSCrypto/JBSCrypto-Prefix.pch

+//
+// Prefix header for all source files of the 'JBSCrypto' target in the 'JBSCrypto' project
+//
+
+#ifdef __OBJC__
+  #import <Foundation/Foundation.h>
+#endif

JBSCrypto/JBSCrypto.h

+//  The MIT License (MIT)
+//  Copyright (c) 2012 James Sumners
+//
+//  Permission is hereby granted, free of charge, to any person obtaining a copy
+//  of this software and associated documentation files (the "Software"), to
+//  deal in the Software without restriction, including without limitation the
+//  rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+//  sell copies of the Software, and to permit persons to whom the Software is
+//  furnished to do so, subject to the following conditions:
+//
+//  The above copyright notice and this permission notice shall be included in
+//  all copies or substantial portions of the Software.
+//
+//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+//  IN THE SOFTWARE.
+
+#import <Foundation/Foundation.h>
+#import <CommonCrypto/CommonCryptor.h>
+#import <CommonCrypto/CommonDigest.h>
+#import <Security/SecRandom.h>
+
+@interface JBSCrypto : NSObject
+#pragma mark - Decryption methods
+/**
+ Decrypts an NSData object that has been encrypted with the
+ encryptData:withKey: method. The same key must be used for decrypting as was
+ used for encrypting.
+ 
+ @param theData The data object to decrypt.
+ @param key The key to use for decrypting.
+ 
+ @return The decrypted data, or nil on error.
+ */
++ (NSData *)decryptData:(NSData *)theData withKey:(NSString *)key;
+
+#pragma mark - Encryption methods
+/**
+ Encrypts an NSData object via the AES 128 algorithm given an AES 256 key.
+ The key is expected to be an NSASCIIStringEncoding based string (i.e. one
+ generated via one of the key generation methods of this class).
+ 
+ @param theData The data to encrypt.
+ @param key The AES 256 key to use for encryption.
+ 
+ @return An NSData object that represents the encrypted data.
+ */
++ (NSData *)encryptData:(NSData *)theData withKey:(NSString *)key;
+
+#pragma mark - Key generating methods
+/**
+ Generates an SHA256 hash that can be used as an AES 256 key. The result is a
+ string With NSASCIIStringEncoding.
+ 
+ This method generates the key from a set of random 1024 bytes.
+ 
+ @return A SHA256 hash.
+ */
++ (NSString *)generateKey;
+
+/**
+ Generates an SHA256 hash that can be used as an AES 256 key. The result is a
+ string with NSASCIIStringEncoding.
+ 
+ @param theData An NSData object to hash.
+ 
+ @return A SHA256 hash.
+ */
++ (NSString *)generateKeyFromData:(NSData *)theData;
+
+/**
+ Generates an SHA256 hash that can be used as an AES 256 key. The result is a
+ string with NSASCIIStringEncoding.
+ 
+ @param theString A source string to hash.
+ @param stringEncoding The encoding of the given string.
+ 
+ @return A SHA256 hash.
+ */
++ (NSString *)generateKeyFromString:(NSString *)theString 
+                       withEncoding:(NSStringEncoding)stringEncoding;
+@end

JBSCrypto/JBSCrypto.m

+//  The MIT License (MIT)
+//  Copyright (c) 2012 James Sumners
+//
+//  Permission is hereby granted, free of charge, to any person obtaining a copy
+//  of this software and associated documentation files (the "Software"), to
+//  deal in the Software without restriction, including without limitation the
+//  rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+//  sell copies of the Software, and to permit persons to whom the Software is
+//  furnished to do so, subject to the following conditions:
+//
+//  The above copyright notice and this permission notice shall be included in
+//  all copies or substantial portions of the Software.
+//
+//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+//  IN THE SOFTWARE.
+
+#import "JBSCrypto.h"
+
+@interface JBSCrypto()
++ (NSString *)dataToHexString:(NSData *)theData;
++ (NSData *)generateKeyData:(NSData *)fromData;
+@end
+
+@implementation JBSCrypto
+#pragma mark - Decryption methods
+// Adapted from http://pastie.org/426530
++ (NSData *)decryptData:(NSData *)theData withKey:(NSString *)key
+{
+  NSData *returnData = nil;
+  char keyCStr[kCCKeySizeAES256+1];
+  bzero(keyCStr, sizeof(keyCStr));
+  
+  [key
+   getCString:keyCStr
+   maxLength:sizeof(keyCStr)
+   encoding:NSASCIIStringEncoding];
+  
+  NSUInteger dataLength = [theData length];
+  size_t bufferSize = dataLength + kCCBlockSizeAES128;
+  void *buffer = malloc(bufferSize);
+  
+  size_t bytesDecrypted = 0;
+  CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt,
+                                        kCCAlgorithmAES128,
+                                        kCCOptionPKCS7Padding,
+                                        keyCStr,
+                                        kCCKeySizeAES256,
+                                        NULL,
+                                        [theData bytes],
+                                        dataLength,
+                                        buffer,
+                                        bufferSize,
+                                        &bytesDecrypted);
+  
+  if (cryptStatus == kCCSuccess) {
+    returnData = [NSData dataWithBytes:buffer length:bytesDecrypted];
+  }
+  
+  return returnData;
+}
+
+#pragma mark - Encryption methods
++ (NSData *)encryptData:(NSData *)theData withKey:(NSString *)key
+{
+  NSData *returnData = nil;
+  char keyCStr[kCCKeySizeAES256+1];
+  bzero(keyCStr, sizeof(keyCStr));
+  
+  [key
+   getCString:keyCStr
+   maxLength:sizeof(keyCStr)
+   encoding:NSASCIIStringEncoding];
+  
+  NSUInteger dataLength = [theData length];
+  size_t bufferSize = dataLength + kCCBlockSizeAES128;
+  void *buffer = malloc(bufferSize);
+  
+  size_t bytesEncrypted = 0;
+  CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,
+                                        kCCAlgorithmAES128,
+                                        kCCOptionPKCS7Padding,
+                                        keyCStr,
+                                        kCCKeySizeAES256,
+                                        NULL,
+                                        [theData bytes],
+                                        dataLength,
+                                        buffer,
+                                        bufferSize,
+                                        &bytesEncrypted);
+  
+  if (cryptStatus == kCCSuccess) {
+    returnData = [NSData dataWithBytes:buffer length:bytesEncrypted];
+  }
+  
+  return returnData;
+}
+
+#pragma mark - Key generating methods
++ (NSString *)generateKey
+{
+  uint8_t randomBytes[1024];
+  int result = SecRandomCopyBytes(kSecRandomDefault, 1024, randomBytes);
+  NSString *returnString = nil;
+  
+  if (result == 0) {
+    returnString = [self
+                    generateKeyFromData:
+                    [NSData dataWithBytes:randomBytes length:1024]];
+  }
+  
+  return returnString;
+}
+
++ (NSString *)generateKeyFromData:(NSData *)theData
+{
+  NSData *keyData = [self generateKeyData:theData];
+  return [self dataToHexString:keyData];
+}
+
++ (NSString *)generateKeyFromString:(NSString *)theString 
+                       withEncoding:(NSStringEncoding)stringEncoding
+{
+  NSData *data = [theString dataUsingEncoding:stringEncoding];
+  NSData *keyData = [self generateKeyData:data];
+  
+  return [self dataToHexString:keyData];
+}
+
+#pragma mark - Private methods
++ (NSString *)dataToHexString:(NSData *)theData
+{
+  NSMutableString *hexString = [NSMutableString stringWithCapacity:0];
+  Byte *cstr = (unsigned char *)[theData bytes];
+  for (int i = 0, j = (int)[theData length]; i < j; i += 1) {
+    [hexString appendFormat:@"%02X", cstr[i]];
+  }
+  
+  return hexString;
+}
+
++ (NSData *)generateKeyData:(NSData *)fromData
+{
+  unsigned char messageDigest[CC_SHA256_DIGEST_LENGTH];
+  CC_SHA256([fromData bytes], (CC_LONG)[fromData length], messageDigest);
+  return [NSData dataWithBytes:messageDigest length:CC_SHA256_DIGEST_LENGTH];
+}
+@end
+//  The MIT License (MIT)
+//  Copyright (c) 2012 James Sumners
+//
+//  Permission is hereby granted, free of charge, to any person obtaining a copy
+//  of this software and associated documentation files (the "Software"), to
+//  deal in the Software without restriction, including without limitation the
+//  rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+//  sell copies of the Software, and to permit persons to whom the Software is
+//  furnished to do so, subject to the following conditions:
+//
+//  The above copyright notice and this permission notice shall be included in
+//  all copies or substantial portions of the Software.
+//
+//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+//  IN THE SOFTWARE.
+
+#import <Foundation/Foundation.h>
+#import "JBSCrypto.h"
+
+int main(int argc, const char * argv[])
+{
+  
+  @autoreleasepool {
+    // echo "This is a test string." | tr -d '\n' | openssl dgst -sha256
+    // 3eec256a587cccf72f71d2342b6dfab0bbca01697c7e7014540bdd62b72120da
+    NSString *stringToEncode = @"This is a test string.";
+    NSString *encodedString = [JBSCrypto 
+                               generateKeyFromData:
+                               [stringToEncode 
+                                dataUsingEncoding:NSASCIIStringEncoding]];
+    
+    NSLog(@"Key = %@", encodedString);
+    
+    encodedString = [JBSCrypto
+                     generateKeyFromString:stringToEncode
+                     withEncoding:NSASCIIStringEncoding];
+    
+    NSLog(@"Key = %@", encodedString);
+    NSLog(@"Random hash = %@", [JBSCrypto generateKey]);
+    
+    
+    // Test encrypting and decrypting.
+    NSURL *url = [NSURL
+                  URLWithString:@"http://textfiles.com/computers/apple.txt"];
+    NSData *dataToEncrypt = [NSData dataWithContentsOfURL:url];
+    NSData *encryptedData = [JBSCrypto
+                             encryptData:dataToEncrypt
+                             withKey:encodedString];
+    NSData *decryptedData = [JBSCrypto
+                             decryptData:encryptedData
+                             withKey:encodedString];
+    
+    if ([decryptedData isEqualToData:dataToEncrypt]) {
+      NSLog(@"Encryption and decryption works.");
+    } else {
+      NSLog(@"Encryption and decryption failed!");
+    }
+  }
+  return 0;
+}
+