开发者

AES test on iphone

开发者 https://www.devze.com 2023-01-20 11:58 出处:网络
my encryption is working but i cant decrypt kindly suggest what i am doing wrong here NSString *passphrase = @\"hello\";

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消