From d405190e35f114c07449e03cacbec2f69e162959 Mon Sep 17 00:00:00 2001 From: Felix Schulze Date: Sat, 4 Dec 2010 15:42:16 +0100 Subject: [PATCH] Using MD5_DIGEST_LENGTH --- Classes/OpenSSL_for_iOSAppDelegate.m | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Classes/OpenSSL_for_iOSAppDelegate.m b/Classes/OpenSSL_for_iOSAppDelegate.m index c257197..b9b9fce 100644 --- a/Classes/OpenSSL_for_iOSAppDelegate.m +++ b/Classes/OpenSSL_for_iOSAppDelegate.m @@ -16,24 +16,21 @@ #pragma mark - -#pragma mark Application lifecycle - -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - [window makeKeyAndVisible]; - return YES; -} +#pragma mark OpenSSL - (IBAction)calculateMD5:(id)sender { /** Calculate MD5*/ NSString *string = textField.text; - unsigned char result[16]; unsigned char *inStrg = (unsigned char*)[[string dataUsingEncoding:NSASCIIStringEncoding] bytes]; unsigned long lngth = [string length]; + unsigned char result[MD5_DIGEST_LENGTH]; + NSMutableString *outStrg = [NSMutableString string]; + MD5(inStrg, lngth, result); - NSMutableString *outStrg = [NSMutableString string]; + unsigned int i; - for (i = 0; i < 16; i++) + for (i = 0; i < MD5_DIGEST_LENGTH; i++) { [outStrg appendFormat:@"%02x", result[i]]; } @@ -56,7 +53,8 @@ SHA256_Init(&sha256); SHA256_Update(&sha256, inStrg, lngth); SHA256_Final(result, &sha256); - int i = 0; + + unsigned int i; for(i = 0; i < SHA256_DIGEST_LENGTH; i++) { [outStrg appendFormat:@"%02x", result[i]]; @@ -67,6 +65,14 @@ [textField resignFirstResponder]; } +#pragma mark - +#pragma mark Application lifecycle + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + [window makeKeyAndVisible]; + return YES; +} + - (IBAction)showInfo { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"OpenSSL-for-iOS" message:@"OpenSSL-Version: 1.0.0c\nLicense: See include/LICENSE\n\nCopyright 2010 by Felix Schulze\n http://www.x2on.de" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];