Hello,
I am using your code to replicate it within an application that I am developing.
I currently have the following problem:
fatal error: Unknown AES variant for given key.
I have assigned and copied the code as until now you have it in the published github.
I am using version 0.6.9 of CryptoSwift to be compatible with Xcode 8.3.3 and Swift 3.
I attached the code of my ViewController.swift
`//
// ViewController.swift
// Seguridad
//
// Created by Alberto on 9/25/17.
// Copyright © 2017. All rights reserved.
//
import UIKit
import CryptoSwift
class ViewController: UIViewController {
@IBOutlet weak var texto1: UITextField!
@IBOutlet weak var texto2: UITextField!
@IBOutlet weak var botonEncriptar: UIButton!
@IBOutlet weak var salidaEncriptar: UITextField!
@IBOutlet weak var textoEncriptado: UITextField!
@IBOutlet weak var tokenEncriptado: UITextField!
@IBOutlet weak var botonDesencriptar: UIButton!
@IBOutlet weak var salidaDesencriptar: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func btnEncriptar(_ sender: UIButton) {
//Traemos lo que haya en la caja de texto
let input = texto1.text
print("Ingreso ",input)
//Traemos lo que haya en el token de encripcion
//aHacemos el proceso
let key = texto2.text
//print("Ingreso 2 ",key)
//Nuestro IV para encripcion
let iv = "gqLOHUioQ0QjhuvI"
// print("Ingreso 3 ",iv)
//Hacemos aqui el metodo de encripcion
let en = try! input!.aesEncrypt(key: key!, iv: iv)
//Lo mandamos a la caja de texto de saida
salidaEncriptar.text = "Token -> "+en
}
}
extension String{
func aesEncrypt(key: String, iv: String) throws -> String {
let data = self.data(using: .utf8)!
//let encrypted = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7()).encrypt(UInt8)
let encrypted = try! AES(key: key, iv: iv).encrypt(UInt8) // aes128
let encryptedData = Data(encrypted)
return encryptedData.base64EncodedString()
}
func aesDecrypt(key: String, iv: String) throws -> String {
let data = Data(base64Encoded: self)!
let decrypted = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7()).decrypt([UInt8](data))
let decryptedData = Data(decrypted)
return String(bytes: decryptedData.bytes, encoding: .utf8) ?? "Could not decrypt"
}
}
`
Hello,
I am using your code to replicate it within an application that I am developing.
I currently have the following problem:
fatal error: Unknown AES variant for given key.
I have assigned and copied the code as until now you have it in the published github.
I am using version 0.6.9 of CryptoSwift to be compatible with Xcode 8.3.3 and Swift 3.
I attached the code of my ViewController.swift
`//
// ViewController.swift
// Seguridad
//
// Created by Alberto on 9/25/17.
// Copyright © 2017. All rights reserved.
//
import UIKit
import CryptoSwift
class ViewController: UIViewController {
}
extension String{
func aesEncrypt(key: String, iv: String) throws -> String {
let data = self.data(using: .utf8)!
//let encrypted = try! AES(key: key, iv: iv, blockMode: .CBC, padding: PKCS7()).encrypt(UInt8)
let encrypted = try! AES(key: key, iv: iv).encrypt(UInt8) // aes128
let encryptedData = Data(encrypted)
return encryptedData.base64EncodedString()
}
}
`