2012-09-05 6 views
-1

아래의 방법을 사용하십시오. 인코딩 된 메시지가 서버로부터 수신 한 1EF5F2D644FBA8E4142778CD43D70BFAJAX (AES Decryption 128)로 암호화 된 iOS에서 메시지를 해독하는 방법 (AES128)

:

의 핵심은 진수의 서버에서 수신/lGtPU2K29FZPNtrc9DKow ==

우리는 위의 메시지를 해독하면 그것은 내가

"안녕하세요"해야한다 iOS 측에서 해독 할 수 없습니다. 누구든지 나를 도울 수 있습니까?

- (NSData *)AES128DecryptWithKey:(NSString *)key 
{ 
    // 'key' should be 16 bytes for AES128, will be null-padded otherwise 
    char keyPtr[kCCKeySizeAES128+1]; // room for terminator (unused) 
    bzero(keyPtr, sizeof(keyPtr)); // fill with zeroes (for padding) 

    // fetch key data 
    [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding]; 

    NSUInteger dataLength = [self length]; 

    //See the doc: For block ciphers, the output size will always be less than or 
    //equal to the input size plus the size of one block. 
    //That's why we need to add the size of one block here 
    size_t bufferSize = dataLength + kCCBlockSizeAES128; 
    void *buffer = malloc(bufferSize); 

    size_t numBytesDecrypted = 0; 
    CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, 0,keyPtr, kCCKeySizeAES128, 
              NULL /* initialization vector (optional) */, 
              [self bytes], dataLength, /* input */ 
              buffer, bufferSize, /* output */ 
              &numBytesDecrypted); 

    if (cryptStatus == kCCSuccess) 
    { 
     //the returned NSData takes ownership of the buffer and will free it on deallocation 
     return [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted]; 
    } 

    free(buffer); //free the buffer; 
    return nil; 
} 
+0

는 텍스트를 암호화 자바 코드를 추가 할 수 있습니까? – rayyildiz

+0

@rayyildiz : 아래 자바 코드를 찾으십시오. –

답변

0

이 시도 할 수 :

CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, 
             kCCAlgorithmAES128, 
             kCCOptionECBMode | kCCOptionPKCS7Padding, 
             keyPtr, 
             kCCKeySizeAES128, 
             NULL /* initialization vector (optional) */, 
             [self bytes], dataLength, /* input */ 
             buffer, bufferSize, /* output */ 
             &numBytesDecrypted); 
+0

제공 한 코드로 시도했지만 데이터가 반환되지 않습니다. 그러나 이전에 사용했던 코드가 데이터를 반환합니다. 그러나 데이터를 문자열로 변환하는 동안. 빈 문자열이 나옵니다. NSString * str = [[NSString alloc] initWithData : 디코딩 된 데이터 인코딩 : NSUTF8StringEncoding]; –

+0

자바 코드가 모드 및 패딩을 사용하고 있지 않습니다. –

+0

안녕하세요 sudhir, 당신도 당신이 위에서 언급 한 같은 문제에 직면 오전 때문에이 문제를 해결했습니다. 이 문제를 해결 한 경우 코드 스 니펫을 제공해주세요. 미리 감사드립니다. –