{"action":"created","issue":{"url":"https://api.github.com/repos/iosdevzone/IDZSwiftCommonCrypto/issues/9","labels_url":"https://api.github.com/repos/iosdevzone/IDZSwiftCommonCrypto/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/iosdevzone/IDZSwiftCommonCrypto/issues/9/comments","events_url":"https://api.github.com/repos/iosdevzone/IDZSwiftCommonCrypto/issues/9/events","html_url":"https://github.com/iosdevzone/IDZSwiftCommonCrypto/issues/9","id":122866379,"number":9,"title":"DES Encryption and Decryption not working","user":{"login":"jaytrixz","id":1453309,"avatar_url":"https://avatars.githubusercontent.com/u/1453309?v=3","gravatar_id":"","url":"https://api.github.com/users/jaytrixz","html_url":"https://github.com/jaytrixz","followers_url":"https://api.github.com/users/jaytrixz/followers","following_url":"https://api.github.com/users/jaytrixz/following{/other_user}","gists_url":"https://api.github.com/users/jaytrixz/gists{/gist_id}","starred_url":"https://api.github.com/users/jaytrixz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaytrixz/subscriptions","organizations_url":"https://api.github.com/users/jaytrixz/orgs","repos_url":"https://api.github.com/users/jaytrixz/repos","events_url":"https://api.github.com/users/jaytrixz/events{/privacy}","received_events_url":"https://api.github.com/users/jaytrixz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-12-18T02:34:35Z","updated_at":"2015-12-18T19:21:12Z","closed_at":null,"body":"I'm trying to use the DES encryption using ECB mode but it's not working. I validate it using the online encryption tool that works. I changed my keys and plain text to not display our own key and text and used a different pair. IDZSwiftCommonCrypto yields different results everytime I tap my Start button. Here's my code:\r\n\r\n```swift\r\nimport UIKit\r\nimport IDZSwiftCommonCrypto\r\n\r\nclass ViewController: UIViewController {\r\n    \r\n    @IBOutlet weak var keyTextField: UITextField! // key is thekey\r\n    @IBOutlet weak var plainTextField: UITextField! // plain text is username123\r\n    @IBOutlet weak var outputTextView: UITextView! // output should be b742acfaa07e3d05cf2dc9aaa0258fc2\r\n    @IBOutlet weak var encryptionSegmentedControl: UISegmentedControl!\r\n    \r\n    override func viewDidLoad() {\r\n        super.viewDidLoad()\r\n        \r\n        UIApplication.sharedApplication().statusBarStyle = .LightContent\r\n    }\r\n\r\n    override func didReceiveMemoryWarning() {\r\n        super.didReceiveMemoryWarning()\r\n        // Dispose of any resources that can be recreated.\r\n    }\r\n    \r\n    \r\n    @IBAction func startButtonTapped(sender: UIButton) {\r\n        if encryptionSegmentedControl.selectedSegmentIndex == 0 {\r\n            let hexKey = arrayFromHexString(convertToHexFromString(keyTextField.text!))\r\n            let encryptedBytesArray = Cryptor(operation:.Encrypt, algorithm:.DES, options:.ECBMode, key:hexKey, iv:[UInt8]()).update(arrayFromHexString(convertToHexFromString(plainTextField.text!)))?.final()\r\n            \r\n            outputTextView.text = hexStringFromArray(encryptedBytesArray!)\r\n        } else {\r\n            let hexKey = arrayFromHexString(convertToHexFromString(keyTextField.text!))\r\n            let decryptedBytesArray = Cryptor(operation:.Decrypt, algorithm:.DES, options:.ECBMode, key:hexKey, iv:[UInt8]()).update(plainTextField.text!)?.final()\r\n            \r\n            outputTextView.text = hexStringFromArray(decryptedBytesArray!)\r\n        }\r\n    }\r\n    \r\n    // MARK: - Custom\r\n    \r\n    @IBAction func dismissKeyboard() {\r\n        self.view.endEditing(true)\r\n    }\r\n    \r\n    func convertToHexFromString(rawString: String) -> String! {\r\n        var hexString = \"\\(rawString.dataUsingEncoding(NSUTF8StringEncoding)!)\"\r\n        hexString = hexString.stringByReplacingOccurrencesOfString(\" \", withString: \"\").stringByTrimmingCharactersInSet(NSCharacterSet.symbolCharacterSet())\r\n        \r\n        print(\"Formatted hex string: \\(hexString)\")\r\n        \r\n        return hexString\r\n    }\r\n    \r\n    func encryptUsingText(hexText: String, hexKey: [UInt8]) -> String! {\r\n        let cryptor = Cryptor(operation:.Encrypt, algorithm:.DES, options:.ECBMode, key:hexKey, iv:[UInt8]())\r\n        let cipherText = cryptor.update(hexText)?.final()\r\n        \r\n        print(\"Bytes array: \\(cipherText!)\")\r\n        \r\n        return String(bytes: cipherText!, encoding: NSUTF8StringEncoding)\r\n    }\r\n    \r\n    func decryptUsingText(rawText: String, hexKey: [UInt8]) -> String! {\r\n        let cryptor = Cryptor(operation:.Decrypt, algorithm:.DES, options:.None, key:hexKey, iv:[UInt8]())\r\n        let decryptedCipherText = cryptor.update(rawText)?.final()\r\n        \r\n        print(\"Bytes array: \\(decryptedCipherText!)\")\r\n        \r\n        return String(bytes: decryptedCipherText!, encoding: NSUTF8StringEncoding)\r\n    }\r\n    \r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/iosdevzone/IDZSwiftCommonCrypto/issues/comments/165875622","html_url":"https://github.com/iosdevzone/IDZSwiftCommonCrypto/issues/9#issuecomment-165875622","issue_url":"https://api.github.com/repos/iosdevzone/IDZSwiftCommonCrypto/issues/9","id":165875622,"user":{"login":"iosdevzone","id":3867014,"avatar_url":"https://avatars.githubusercontent.com/u/3867014?v=3","gravatar_id":"","url":"https://api.github.com/users/iosdevzone","html_url":"https://github.com/iosdevzone","followers_url":"https://api.github.com/users/iosdevzone/followers","following_url":"https://api.github.com/users/iosdevzone/following{/other_user}","gists_url":"https://api.github.com/users/iosdevzone/gists{/gist_id}","starred_url":"https://api.github.com/users/iosdevzone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iosdevzone/subscriptions","organizations_url":"https://api.github.com/users/iosdevzone/orgs","repos_url":"https://api.github.com/users/iosdevzone/repos","events_url":"https://api.github.com/users/iosdevzone/events{/privacy}","received_events_url":"https://api.github.com/users/iosdevzone/received_events","type":"User","site_admin":false},"created_at":"2015-12-18T19:21:12Z","updated_at":"2015-12-18T19:21:12Z","body":"Sorry, there was a typo in the code in my comment above. Have corrected it now. Problem was that type of initialization vector must match. It was\r\n```swift\r\nlet cryptor = Cryptor(operation: .Encrypt, algorithm: .DES, options: [.ECBMode], key: key, iv:[UInt8]())\r\n```\r\nShould be \r\n```swift\r\nlet cryptor = Cryptor(operation: .Encrypt, algorithm: .DES, options: [.ECBMode], key: key, iv:\"\")\r\n```\r\n"}}