2

I am using Cryptoswift framework for encryption and decryption. I am using an Xcode project inside another Xcode project.The subproject is not able to access the framework Cryptoswift in spite of using pods for the main project. In addition to that, I have also added the framework to the "Linked Frameworks and Libraries".The Project works fine in the simulator but is not working on the device.When I run it on the device I get the error

  var enc = try AES(key: FirstStepEncryptionKey, iv: "", blockMode:.CBC, padding: NoPadding()).encrypt(firstStepArray)

ERROR:"Use of unresolved identifier 'AES'"

Though the import statement does not show any errors.I am the only developer in my company and there is no one to guide me.Please help me clear this.

UPDATE: I added the files to embed binary and still it crashes saying "dyld: Library not loaded: @rpath/CryptoSwift.framework/CryptoSwift Referenced from: /var/containers/Bundle/Application/48894FB2-0CDB-4B8D-A763-1C57B3EDAE41/Vaya_Tracker.app/Vaya_Tracker Reason: image not found"

Fix: I had to add the CryptoSwift.xcodeproj file into my Xcode project instead of adding it through pods or Carthage.

tamizhachi_
  • 65
  • 10
  • It is best to avoid using CryptoSwift, amoung other things it is 500 to 1000 times slower than Common Crypto based implementations. Apple's Common Crypto is FIPS certified and as such has been well vetted, using CryptoSwift is taking a chance on correctness and security such as timing and power attacks. – zaph Mar 22 '18 at 12:55

1 Answers1

2

I am also using CryptoSwift with Cocoapods and Swift version is Swift 4.0. Below is my podfile.

platform :ios, '8.0'
use_frameworks!

target 'MyAProjectName' do
 pod 'CryptoSwift', '0.8.3'
end

You have to import CryptoSwift to make use of AES.

import CryptoSwift

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        do {
            let aes = try AES(key: "passwordpassword", iv: "drowssapdrowssap") // aes128
            let ciphertext = try aes.encrypt(Array("Nullam quis risus eget urna mollis ornare vel eu leo.".utf8))
            print(ciphertext)
        } catch { }

    }
}

Update for crash issue as per comment :

enter image description here

Then clean the build and build again. If still it not work than try to set status in Linked framework and Libraries as required for both frameworks.

technerd
  • 14,144
  • 10
  • 61
  • 92
  • Thank you, but now I am able to run the app in the simulator without any issues but when I am running it on the device it crashes saying dyld: Library not loaded: @rpath/CryptoSwift.framework/CryptoSwift Referenced from: /var/containers/Bundle/Application/48894FB2-0CDB-4B8D-A763-1C57B3EDAE41/Vaya_Tracker.app/Vaya_Tracker Reason: image not found. can anyone help me please – tamizhachi_ Mar 22 '18 at 07:27
  • Are you using pod ? – technerd Mar 22 '18 at 07:31
  • Add `CryptoSwift.framework` in `Embed Binaries` and `Linked Frameworks and Libraries`. – technerd Mar 22 '18 at 07:46
  • post your crash logs and i am suggesting solution for pod. – technerd Mar 22 '18 at 07:59
  • crash log : dyld: Library not loaded: @rpath/CryptoSwift.framework/CryptoSwift Referenced from: /var/containers/Bundle/Application/48894FB2-0CDB-4B8D-A763-1C57B3EDAE41/Vaya_Tracker.app/Vaya_Tracker Reason: image not found – tamizhachi_ Mar 22 '18 at 08:03
  • Image not found error suggest that, you have not embedded framework in application. – technerd Mar 22 '18 at 08:44
  • how do I do that – tamizhachi_ Mar 22 '18 at 08:49
  • I have posted image in answer to embed and link framework. Thats is the solution for image not found. Also delete the installed build first from device then run. – technerd Mar 22 '18 at 08:50
  • I had to add the CryptoSwift.xcodeproj file into my Xcode project instead of adding it through pods or Carthage. – tamizhachi_ Jul 20 '18 at 09:36