From 11d752b24d9acc02ecd086bd80d17cdb902ba771 Mon Sep 17 00:00:00 2001 From: Felix Schulze Date: Sat, 4 Dec 2010 14:46:33 +0100 Subject: [PATCH] SHA256 with OpenSSL --- Classes/OpenSSL_for_iPhoneAppDelegate.h | 8 +- Classes/OpenSSL_for_iPhoneAppDelegate.m | 30 +++- MainWindow.xib | 200 ++++++++++++++++++------ OpenSSL_for_iPhone-Info.plist | 2 + 4 files changed, 191 insertions(+), 49 deletions(-) diff --git a/Classes/OpenSSL_for_iPhoneAppDelegate.h b/Classes/OpenSSL_for_iPhoneAppDelegate.h index 6600793..6fcf11e 100644 --- a/Classes/OpenSSL_for_iPhoneAppDelegate.h +++ b/Classes/OpenSSL_for_iPhoneAppDelegate.h @@ -12,15 +12,19 @@ UIWindow *window; IBOutlet UITextField *textField; - IBOutlet UITextField *md5TextField; + IBOutlet UILabel *md5TextField; + IBOutlet UILabel *sha256TextField; + } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UITextField *textField; -@property (nonatomic, retain) IBOutlet UITextField *md5TextField; +@property (nonatomic, retain) IBOutlet UILabel *md5TextField; +@property (nonatomic, retain) IBOutlet UILabel *sha256TextField; - (IBAction)showInfo; - (IBAction)calculateMD5:(id)sender; +- (IBAction)calculateSHA256:(id)sender; @end diff --git a/Classes/OpenSSL_for_iPhoneAppDelegate.m b/Classes/OpenSSL_for_iPhoneAppDelegate.m index 604bd06..401ca0a 100644 --- a/Classes/OpenSSL_for_iPhoneAppDelegate.m +++ b/Classes/OpenSSL_for_iPhoneAppDelegate.m @@ -8,10 +8,11 @@ #import "OpenSSL_for_iPhoneAppDelegate.h" #include +#include @implementation OpenSSL_for_iPhoneAppDelegate -@synthesize window, textField, md5TextField; +@synthesize window, textField, md5TextField, sha256TextField; #pragma mark - @@ -37,6 +38,33 @@ [outStrg appendFormat:@"%02x", result[i]]; } md5TextField.text = outStrg; + + //Hide Keyboard after calculation + [textField resignFirstResponder]; +} + +- (IBAction)calculateSHA256:(id)sender { + + /* Calculate SHA256 */ + NSString *string = textField.text; + unsigned char *inStrg = (unsigned char*)[[string dataUsingEncoding:NSASCIIStringEncoding] bytes]; + unsigned long lngth = [string length]; + unsigned char result[SHA256_DIGEST_LENGTH]; + NSMutableString *outStrg = [NSMutableString string]; + + SHA256_CTX sha256; + SHA256_Init(&sha256); + SHA256_Update(&sha256, inStrg, lngth); + SHA256_Final(result, &sha256); + int i = 0; + for(i = 0; i < SHA256_DIGEST_LENGTH; i++) + { + [outStrg appendFormat:@"%02x", result[i]]; + } + sha256TextField.text = outStrg; + + //Hide Keyboard after calculation + [textField resignFirstResponder]; } - (IBAction)showInfo { diff --git a/MainWindow.xib b/MainWindow.xib index 0353d21..1c3c6c4 100644 --- a/MainWindow.xib +++ b/MainWindow.xib @@ -101,7 +101,7 @@ 1316 - {{86, 142}, {147, 35}} + {{19, 142}, {286, 35}} NO IBCocoaTouchFramework @@ -120,7 +120,7 @@ 1316 - {{20, 185}, {87, 21}} + {{19, 230}, {87, 21}} NO YES @@ -136,30 +136,21 @@ 1 10 - + 1316 - {{20, 214}, {285, 31}} + {{19, 298}, {115, 21}} NO YES + 7 + NO IBCocoaTouchFramework - NO - 0 - - 3 - - 3 - MAA - - 2 - - - YES - 17 - - IBCocoaTouchFramework - + SHA256-Hash: + + + 1 + 10 @@ -175,7 +166,9 @@ 3 MAA - + + 2 + YES 17 @@ -199,6 +192,58 @@ 1 10 + + + 1316 + {{19, 185}, {286, 37}} + + NO + IBCocoaTouchFramework + 0 + 0 + + 1 + Calculate SHA256 + + + 1 + MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA + + + + + + 1316 + {{20, 259}, {285, 31}} + + NO + YES + 7 + NO + IBCocoaTouchFramework + + + + 1 + 10 + + + + 1316 + {{19, 327}, {286, 62}} + + NO + YES + 7 + NO + IBCocoaTouchFramework + + + + 1 + 10 + 3 + {320, 480} @@ -242,14 +287,6 @@ 20 - - - md5TextField - - - - 26 - textField @@ -267,6 +304,31 @@ 32 + + + calculateSHA256: + + + 1 + + 34 + + + + md5TextField + + + + 44 + + + + sha256TextField + + + + 46 + @@ -285,9 +347,12 @@ + - + + + @@ -349,11 +414,6 @@ - - 25 - - - 29 @@ -364,6 +424,26 @@ + + 33 + + + + + 35 + + + + + 43 + + + + + 45 + + + @@ -383,14 +463,19 @@ 22.IBViewBoundsToFrameTransform 24.IBPluginDependency 24.IBViewBoundsToFrameTransform - 25.IBPluginDependency - 25.IBViewBoundsToFrameTransform 29.IBPluginDependency 29.IBViewBoundsToFrameTransform 3.CustomClassName 3.IBPluginDependency 30.IBPluginDependency 30.IBViewBoundsToFrameTransform + 33.IBPluginDependency + 33.IBViewBoundsToFrameTransform + 35.IBPluginDependency + 35.IBViewBoundsToFrameTransform + 43.IBPluginDependency + 43.IBViewBoundsToFrameTransform + 45.IBPluginDependency YES @@ -413,15 +498,11 @@ com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin - P4AAAL+AAABCrAAAw4CAAA + P4AAAL+AAABBmAAAwy8AAA com.apple.InterfaceBuilder.IBCocoaTouchPlugin - P4AAAL+AAABBoAAAw7OAAA - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - P4AAAL+AAABBoAAAw8cAAA + P4AAAL+AAABBiAAAw4aAAA com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -433,6 +514,19 @@ P4AAAL+AAABBmAAAwrYAAA + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + P4AAAL+AAABBMAAAw1wAAA + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + P4AAAL+AAABBiAAAw6iAAA + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + P4AAAL+AAABCuAAAw4sAAA + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -451,7 +545,7 @@ - 32 + 46 @@ -464,12 +558,14 @@ YES calculateMD5: + calculateSHA256: showInfo YES id id + id @@ -477,6 +573,7 @@ YES calculateMD5: + calculateSHA256: showInfo @@ -485,6 +582,10 @@ calculateMD5: id + + calculateSHA256: + id + showInfo id @@ -496,12 +597,14 @@ YES md5TextField + sha256TextField textField window YES - UITextField + UILabel + UILabel UITextField UIWindow @@ -511,6 +614,7 @@ YES md5TextField + sha256TextField textField window @@ -518,7 +622,11 @@ YES md5TextField - UITextField + UILabel + + + sha256TextField + UILabel textField diff --git a/OpenSSL_for_iPhone-Info.plist b/OpenSSL_for_iPhone-Info.plist index a8ea854..2cce138 100644 --- a/OpenSSL_for_iPhone-Info.plist +++ b/OpenSSL_for_iPhone-Info.plist @@ -2,6 +2,8 @@ + UIApplicationExitsOnSuspend + CFBundleDevelopmentRegion English CFBundleDisplayName