在Objective-C解密节点j中进行encryption

我正在encryption一些文本我想发送到服务器,我没有问题encryption,并在Objective-C解密,但是当我发送到nodejs服务器的结果解密它永远不会正确的encryption数据总是来相同…我认为问题是我如何使用encryption库,这里是我的Xcode代码:

NSString * key =@"1234567890123456"; NSString * url = @"http://flystory.herokuapp.com/register"; NSString *post = @"hola mundo!!!!!!!!!!"; NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSLog(@"%@",[[NSString alloc] initWithData:postData encoding:NSASCIIStringEncoding]); NSError *e; CCCryptorStatus err; postData = [postData dataEncryptedUsingAlgorithm:kCCAlgorithmAES128 key:key options:kCCOptionECBMode error:&err]; NSLog(@"%@",[[NSString alloc] initWithData:postData encoding:NSASCIIStringEncoding]); NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:url]]; [request setHTTPMethod:@"post"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"body" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:postData]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *r, NSData *d, NSError *e) { if (e) NSLog(@"%@",e.description); else [self handleRespondedData:d]; }]; postData = [postData decryptedDataUsingAlgorithm:kCCAlgorithmAES128 key:key options:kCCOptionECBMode error:&err]; NSLog(@"%@",[[NSString alloc] initWithData:postData encoding:NSASCIIStringEncoding]); 

encryption我使用NSData + CommonCrypto.h / m中包含的NSData扩展在https://github.com/Gurpartap/AESCrypt-ObjC

我的Node.JS代码如下所示:

  var express = require("express"); var app = express(express.bodyParser()); //... app.post("*", function(request, response) { var body = ''; request.setEncoding('hex'); request.on('data', function (data) { body += data; var crypto=require('crypto'); var decipher=crypto.createDecipher('aes-128-ecb', '1234567890123456'); decipher.setAutoPadding(auto_padding=false); var enc = decipher.update(body, 'hex', 'utf8') + decipher.final('utf8'); console.log('encrypted: ' + body); console.log('decrypted: ' + enc); }); request.on('end', function () { // use POST route(handle, request.path, response, body); }); });