Using MD5_DIGEST_LENGTH

This commit is contained in:
Felix Schulze 2010-12-04 15:42:16 +01:00
parent f0a37e3db7
commit d405190e35
1 changed files with 16 additions and 10 deletions

View File

@ -16,24 +16,21 @@
#pragma mark - #pragma mark -
#pragma mark Application lifecycle #pragma mark OpenSSL
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window makeKeyAndVisible];
return YES;
}
- (IBAction)calculateMD5:(id)sender - (IBAction)calculateMD5:(id)sender
{ {
/** Calculate MD5*/ /** Calculate MD5*/
NSString *string = textField.text; NSString *string = textField.text;
unsigned char result[16];
unsigned char *inStrg = (unsigned char*)[[string dataUsingEncoding:NSASCIIStringEncoding] bytes]; unsigned char *inStrg = (unsigned char*)[[string dataUsingEncoding:NSASCIIStringEncoding] bytes];
unsigned long lngth = [string length]; unsigned long lngth = [string length];
unsigned char result[MD5_DIGEST_LENGTH];
NSMutableString *outStrg = [NSMutableString string];
MD5(inStrg, lngth, result); MD5(inStrg, lngth, result);
NSMutableString *outStrg = [NSMutableString string];
unsigned int i; unsigned int i;
for (i = 0; i < 16; i++) for (i = 0; i < MD5_DIGEST_LENGTH; i++)
{ {
[outStrg appendFormat:@"%02x", result[i]]; [outStrg appendFormat:@"%02x", result[i]];
} }
@ -56,7 +53,8 @@
SHA256_Init(&sha256); SHA256_Init(&sha256);
SHA256_Update(&sha256, inStrg, lngth); SHA256_Update(&sha256, inStrg, lngth);
SHA256_Final(result, &sha256); SHA256_Final(result, &sha256);
int i = 0;
unsigned int i;
for(i = 0; i < SHA256_DIGEST_LENGTH; i++) for(i = 0; i < SHA256_DIGEST_LENGTH; i++)
{ {
[outStrg appendFormat:@"%02x", result[i]]; [outStrg appendFormat:@"%02x", result[i]];
@ -67,6 +65,14 @@
[textField resignFirstResponder]; [textField resignFirstResponder];
} }
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window makeKeyAndVisible];
return YES;
}
- (IBAction)showInfo { - (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]; 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];