2011-08-02 72 views
0

看到我的代碼:緩衝區太小的SecKeyWrapper,如何解決它?

NSString *requestString = @"I am an encrypted piece of dataaaaaaaaaaaaaaaaaaaa"; 
NSData *xmlDaCriptare1 = [NSData dataWithBytes:[requestString UTF8String] length:[requestString lengthOfBytesUsingEncoding:NSUTF8StringEncoding]]; 


xmlDaCriptare1 = [requestString dataUsingEncoding:NSUTF8StringEncoding]; 

NSString *strcheck = [[NSString alloc] initWithData:xmlDaCriptare1 encoding:NSUTF8StringEncoding]; 

NSLog(@"%@", strcheck); 

char *keya = "a16byteslongkey!"; 

NSData * symmetricKey = [NSData dataWithBytes:keya length:16];  
CCOptions pad = kCCOptionECBMode; 
NSData *xmlCriptato = [[SecKeyWrapper sharedWrapper] doCipher:xmlDaCriptare1 
               key:symmetricKey 
              context:kCCEncrypt 
              padding:&pad]; 

它總是返回:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Problem with encipherment ccStatus == -4301' 

這就是 「緩衝區太小」。任何人都知道如何解決它? 謝謝, 奧蕾莉亞

回答

0

我不知道你正在嘗試做的,你有

NSData *xmlDaCriptare1 = [NSData dataWithBytes:[requestString UTF8String] length:[requestString lengthOfBytesUsingEncoding:NSUTF8StringEncoding]]; 

但做到這一點,其再現您的NSData

xmlDaCriptare1 = [requestString dataUsingEncoding:NSUTF8StringEncoding]; 

完全一樣的字節您strcheck from

NSString *strcheck = [[NSString alloc] initWithData:xmlDaCriptare1 encoding:NSUTF8StringEncoding]; 

也不會脫離,

我假設你正在使用這一示範樣本SecKeyWrapper蘋果CryptoExercise,所以你可能會發現在那裏代碼(這只是畢竟是一個演示程序)中的錯誤,我建議你找出它在哪裏SecKeyWrapper它的失敗,並且如果你仍然不能在發佈那段代碼後發生什麼問題。

+0

謝謝你。我試圖看到代碼,但沒有成功。方法是 - (NSData *)doCipher:(NSData *)plainText key:(NSData *)symmetricKey context:(CCOperation)encryptOrDecrypt padding :(CCOptions *)pkcs7 { – Alleria