Rectangle 27 0

ios How to send CommonCrypto POST request using AES Crypto in Objective c?


#import "CryptoTest-Swift.h"
#import "ViewController.h"
#import "CryptoTest-Swift.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    CryptoHelper *testCrypt = [[CryptoHelper alloc]init];
    [testCrypt cryptTest];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
#import "YourProjectModuleName-Swift.h"
//
//  CryptoHelper.swift
//  CryptoTest

import UIKit
import CryptoSwift

class CryptoHelper: NSObject {
    func cryptTest(){
        /* Hash enum usage */
        let input:[UInt8] = [49, 50, 51]

        let output = input.md5()
        // alternatively: let output = CryptoSwift.Hash.md5(input).calculate()

        print(output.toHexString())
    }
}
platform :ios, '8.0'
use_frameworks!

target 'CryptoTest' do
    pod 'CryptoSwift'
end

Add a helper swift file with bridging header

For that go to the Settings > Packaging > Defines Module = True

Install pods in your project with

Now import the CryptoSwift in The Helper File

We can do it by creating a helper class of Swift in Objective-C project.

Note
Rectangle 27 0

ios How to send CommonCrypto POST request using AES Crypto in Objective c?


If all you need is to send secure request to a web server just use https. Using https encrypts the entire transfer and even any query parameters. You can not do better.

If you need more security use RNCryptor which is available in several languages for several platforms. It is well secure, well vetted and under current development/maintenance. It provides all the details such as a random iv, message authentication, key extension and versioning for strong security.

Note