Encrypted QR Code generation using Flutter — AES Encryption

Vijay R
vijaycreations
Published in
3 min readMay 29, 2021

In this article we will be discussing about how to create a QR code with AES encryption and also scan that QR code to decrypt and get back the original message.

Video Tutorial

Dependencies

flutter_barcode_scanner: ^2.0.0 //for scanning QR
encrypt: ^5.0.0 //for AES encrption
qr_flutter: ^4.0.0 //to generate QR
url_launcher: ^6.0.3 //to launch the link in a browser

Implementation

As a quick intro., In this application, we will be having two buttons, one for creating a QR Code and another for scanning the QR Code.

→ For creating a QR Code we will be getting the input data from the user using textFormField widget and create a QR Code out of it.

→ For scanning the QR Code, we will be making use of the device/system camera to scan the QR widget that was generated from the previous step.

  1. First create a class that defines the key and IV for encryption.

The following functions are used for.,

encryptMsg() => used for creating a hexadecimal string out of plain text.

decryptMsg() => used to decrypt the encrypted hexadecimal string.

getCode() => creates an encryption object from hexadecimal string.

2. Next, encrypt the plain text for generating the QR.

GeneratedQR(encryption.encryptMsg(mycontroller.text).base16)

The “GeneratedQR” is a custom defined class which is responsible for creating a QR Code for the data what we pass as a parameter (i.e., a textformfield data mycontroller.text in our case)

The GeneratedQR class is as follows.,

So far we have completed generating an encrypted QR Code for the given plain text. now let’s move towards scanning the QR Code and decrypt them to get the original plain text.

3. The decryption logic is written inside the onPress() event of a button as follows., [line no: 7–9]

Well… that’s it., We have now implemented AES Encryption with QR Scanner and QR Generator in Flutter.🥳

👨‍💻Get the complete Source Code here 👉🏻: https://github.com/vijayinyoutube/encrypted-QR

Sample Screenshots

--

--

Vijay R
vijaycreations

Hai👋 I’m a flutter developer experienced in designing and developing stunning mobile apps. Reach out for freelance projects: calico.takeoff_01@icloud.com