Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Binju

macrumors member
Original poster
Jan 31, 2010
65
0
I want to encrypted the password text and stored in to the database and also I want to compare the encrypted text with the text in the textbox.

So I want to know , How to convert the normal text in to the encrypted text and encrypted text to the normal text
 
Code:
		NSString *password=@"mypassword" ;
		NSString *str = txtPassword.text;
	 
	 // 1) Encrypt
	 NSLog(@"encrypting string = %@",str);
	 
	 NSData *data = [str dataUsingEncoding: NSASCIIStringEncoding];
	 NSData *encryptedData = [data AESEncryptWithPassphrase:password];
	 
	 // 2) Encode Base 64
	 // If you need to send over internet, encode NSData -> Base64 encoded string
	 [Base64 initialize];
	 NSString *b64EncStr = [Base64 encode:encryptedData];
	 
	 NSLog(@"Base 64 encoded = %@",b64EncStr);
	 
	 //////////////////// Send this data over network /////////////////////////////////////	
	 
	 // 3) Decode Base 64
	 // Then you can put that back like this
	 NSData	*b64DecData = [Base64 decode:password1];
	 
	 // 4) Decrypt
	 // This should be same before encode -> decode base 64
	 //NSData *decryptedData = [encryptedData AESDecryptWithPassphrase:password];
	 NSData *decryptedData = [b64DecData AESDecryptWithPassphrase:password];
	 
	 NSString* decryptedStr = [[NSString alloc] initWithData:decryptedData encoding:NSASCIIStringEncoding];
	 
	 NSLog(@"decrypted string = %@",decryptedStr);

The above code converts to base64.Is it possible to convert to hexadecimal?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.