AES test on iphone
my encryption is working but i cant decrypt kindly suggest what i am doing wrong here
NSString *passphrase = @"hello";
NSStringEncoding myEncoding = NSASCIIStringEncoding;
NSString *alphaStringPlain = @"cell";
NSData *alphaDataPlain = [alphaStringPlain dataUsingEncoding:myEncoding];
NSData *alphaDataCypher = [alphaDataPlain AESEncryptWithPassphrase:passphrase];
NSString *alphaStringCypher = [[NSString alloc] initWithData:alphaDataCypher encoding:myEncoding];
NSLog(alphaStringCypher); // perfeclty encypted i guess
/////// FOR DECRYPTION///////////////
NSData *zCypher = [alphaDataPlain AESDecryptWithPassphrase:alphaStringCypher];
NSString *Cypher = [[NSString alloc] initWithData:zCypher encoding:myEncoding];
NSLog(@" decode开发者_开发百科 %@",[Cypher dataUsingEncoding:NSUTF8StringEncoding]);
NSLog(@" decode %@",Cypher);// not working some garbage value
After struggling i got the ans
NSString *passphrase = @"1234567812345678";
NSStringEncoding myEncoding = NSASCIIStringEncoding;
NSString *alphaStringPlain = @"hello";
NSData *alphaDataPlain = [alphaStringPlain dataUsingEncoding:myEncoding];
NSData *alphaDataCypher = [alphaDataPlain AESEncryptWithPassphrase:passphrase];
NSString *alphaStringCypher = [[NSString alloc] initWithData:alphaDataCypher encoding:myEncoding];
NSLog(alphaStringCypher);
///////
NSData *zCypher = [alphaDataCypher AESDecryptWithPassphrase:passphrase];
NSString *Cypher = [[NSString alloc] initWithData:zCypher encoding:myEncoding];
//NSData *zCypher = [alphaStringCypher AESDecryptWithPassphrase:passphrase];
NSLog(@" hua kya decode %@",cypher);// working
I think you are decrypting wrong value try with this :
NSData *zCypher = [alphaStringCypher AESDecryptWithPassphrase:passphrase];
精彩评论