views:

87

answers:

1

Hello,

I am trying to decrypt the data from last couple of days. I decrypt the data but the result is not same as original. Please, can anyone suggest how I can do this. I am trying to decrypt the following data:

Encrypted Data : "Mmb9tEkmW82oFPJb3vNhHA=="

Encrypt Key : "91860F52E5C3A09BA3B827F28070E08D"

Original data: "Marco"

Please help. Thanks

+1  A: 

Here is how I used AES128

- (NSData *)cipherData:(NSData *)data {
    return [self aesOperation:kCCEncrypt OnData:data];
}

- (NSData *)decipherData:(NSData *)data {
    return [self aesOperation:kCCDecrypt OnData:data];
}


- (NSData *)aesOperation:(CCOperation)op OnData:(NSData *)data {
    NSData *outData = nil;

    // Data in parameters   
    const void *key = cipherKey.bytes;
    const void *dataIn = data.bytes;
    size_t dataInLength = data.length;  
    // Data out parameters
    size_t outMoved = 0;

    // Init out buffer
    unsigned char outBuffer[BUFFER_SIZE];
    memset(outBuffer, 0, BUFFER_SIZE);
    CCCryptorStatus status = -1;

    status = CCCrypt(op, kCCAlgorithmAES128, kCCOptionPKCS7Padding, key, kCCKeySizeAES256, NULL,
                 dataIn, dataInLength, &outBuffer, BUFFER_SIZE, &outMoved);

    if(status == kCCSuccess) {  
        outData = [NSData dataWithBytes:outBuffer length:outMoved];
    } else if(status == kCCBufferTooSmall) {
        // Resize the out buffer
        size_t newsSize = outMoved;
        void *dynOutBuffer = malloc(newsSize);
        memset(dynOutBuffer, 0, newsSize);
        outMoved = 0;

        status = CCCrypt(op, kCCAlgorithmAES128, kCCOptionPKCS7Padding, key, kCCKeySizeAES256, NULL,
                     dataIn, dataInLength, &outBuffer, BUFFER_SIZE, &outMoved);

    if(status == kCCSuccess) {  
        outData = [NSData dataWithBytes:outBuffer length:outMoved];
    }
}

return outData; 
}
Charter