Permalink
Browse files

Added a little example app to show that this actually works. It just …

…calculates a SHA1 digest and displays it in a view.
  • Loading branch information...
1 parent 2490958 commit cef13aba8aed4974a603731080404be32b165021 @st3fan committed Oct 5, 2010
@@ -0,0 +1,22 @@
+//
+// ExampleAppDelegate.h
+// Example
+//
+// Created by Stefan Arentz on 10-10-05.
+// Copyright 2010 Arentz Consulting. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@class ExampleViewController;
+
+@interface ExampleAppDelegate : NSObject <UIApplicationDelegate> {
+ UIWindow *window;
+ ExampleViewController *viewController;
+}
+
+@property (nonatomic, retain) IBOutlet UIWindow *window;
+@property (nonatomic, retain) IBOutlet ExampleViewController *viewController;
+
+@end
+
@@ -0,0 +1,88 @@
+//
+// ExampleAppDelegate.m
+// Example
+//
+// Created by Stefan Arentz on 10-10-05.
+// Copyright 2010 Arentz Consulting. All rights reserved.
+//
+
+#import "ExampleAppDelegate.h"
+#import "ExampleViewController.h"
+
+@implementation ExampleAppDelegate
+
+@synthesize window;
+@synthesize viewController;
+
+
+#pragma mark -
+#pragma mark Application lifecycle
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+
+ // Override point for customization after application launch.
+
+ // Add the view controller's view to the window and display.
+ [window addSubview:viewController.view];
+ [window makeKeyAndVisible];
+
+ return YES;
+}
+
+
+- (void)applicationWillResignActive:(UIApplication *)application {
+ /*
+ Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
+ Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
+ */
+}
+
+
+- (void)applicationDidEnterBackground:(UIApplication *)application {
+ /*
+ Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
+ If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
+ */
+}
+
+
+- (void)applicationWillEnterForeground:(UIApplication *)application {
+ /*
+ Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
+ */
+}
+
+
+- (void)applicationDidBecomeActive:(UIApplication *)application {
+ /*
+ Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
+ */
+}
+
+
+- (void)applicationWillTerminate:(UIApplication *)application {
+ /*
+ Called when the application is about to terminate.
+ See also applicationDidEnterBackground:.
+ */
+}
+
+
+#pragma mark -
+#pragma mark Memory management
+
+- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
+ /*
+ Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
+ */
+}
+
+
+- (void)dealloc {
+ [viewController release];
+ [window release];
+ [super dealloc];
+}
+
+
+@end
@@ -0,0 +1,16 @@
+//
+// ExampleViewController.h
+// Example
+//
+// Created by Stefan Arentz on 10-10-05.
+// Copyright 2010 Arentz Consulting. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface ExampleViewController : UIViewController {
+
+}
+
+@end
+
@@ -0,0 +1,43 @@
+// ExampleViewController.m
+
+#import "ExampleViewController.h"
+
+#include <openssl/evp.h>
+
+@implementation ExampleViewController
+
+static void ToHex(const unsigned char* data, unsigned int length, char* buffer)
+{
+ static char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
+ for (unsigned i = 0; i < length; i++) {
+ *buffer++ = hex[(data[i] & 0xf0) >> 4];
+ *buffer++ = hex[(data[i] & 0x0f)];
+ }
+ *buffer = 0;
+}
+
+- (void) viewDidLoad
+{
+ char message[] = "I like cheese";
+
+ OpenSSL_add_all_digests();
+
+ const EVP_MD* md;
+ unsigned char md_value[EVP_MAX_MD_SIZE];
+ unsigned int md_len;
+ EVP_MD_CTX mdctx;
+
+ md = EVP_get_digestbyname("SHA1");
+
+ EVP_MD_CTX_init(&mdctx);
+ EVP_DigestInit_ex(&mdctx, md, NULL);
+ EVP_DigestUpdate(&mdctx, message, strlen(message));
+ EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
+ EVP_MD_CTX_cleanup(&mdctx);
+
+ char md_hex[(EVP_MAX_MD_SIZE * 2) + 1];
+ ToHex(md_value, md_len, md_hex);
+ [[self.view.subviews objectAtIndex: 0] setText: [NSString stringWithCString: md_hex encoding: NSASCIIStringEncoding]];
+}
+
+@end
View
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleDisplayName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>LSRequiresIPhoneOS</key>
+ <true/>
+ <key>NSMainNibFile</key>
+ <string>MainWindow</string>
+</dict>
+</plist>
Oops, something went wrong.

0 comments on commit cef13ab

Please sign in to comment.