简体   繁体   中英

How to decrypt AES 128 with swift using CryptoSwift framework

I'm working on swift project that is scanning QR codes and getting encrypted AES-128 data that needs to be decrypted.

I'm using a framework that is called CryptoSwift.

I have the key and data from QR code that holds the encrypted data.

var key     = "B7zqj4TAXnPevYZAR4T26969"
var qrData  = "zWDzClfre4aOjTumzGsnpqh4Sje7sFsbKceA3/OSH3nKRwc7/6fYUajBr/bLh9BB"

Edit: Sorry, I forgot to mention that the encryption made with:

  1. Cipher : AES-128
  2. Mode of Operation : CBC
  3. Padding : PKCS7
  4. Key derived from : Simple decoding

I'd like to know what approaches I should do in order to decrypt this QR data.

Any help would be nice.

See this SO answer for sample Swift AES code.

When you say: "Cipher : AES-128" that is ambiguous. presumably you mean a 128-bit key size. The key supplied is 24 bytes which would be a key size of 192-bits.

CBC mode requires an iv but none is specified. Many inmplementations will use 0x00 bytes by default but that is not guaranteed, Common Crypto does. But it is always best to supply the iv.

What do you expect wen you say: "Key derived from : Simple decoding"? The current best practives solution is PBKDF2.

You need a Bridging header and add #import in it. If you dont have a bridging header let the system add one for out, see Adding a Bridging Header , you can delete the .m file after step 3.

You also need to add Security.framework to the project. What version if Swift are you using.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM