How to decrypt of the encrypted value in dart? How to decrypt of the encrypted value in dart? dart dart

How to decrypt of the encrypted value in dart?


The easiest way IMO is to use encrypt:

import 'package:encrypt/encrypt.dart';final key = Key.fromUtf8('put32charactershereeeeeeeeeeeee!'); //32 charsfinal iv = IV.fromUtf8('put16characters!'); //16 chars//encryptString encryptMyData(String text) {  final e = Encrypter(AES(key, mode: AESMode.cbc));  final encrypted_data = e.encrypt(text, iv: iv);  return encrypted_data.base64;}//dycryptString decryptMyData(String text) {  final e = Encrypter(AES(key, mode: AESMode.cbc));  final decrypted_data = e.decrypt(Encrypted.fromBase64(text), iv: iv);  return decrypted_data;}


An HMAC is a message authentication code. It is a digest used to verify that a message has not been tampered with, similar to a signature. It is constructed using a one-way hash function, in this case SHA256. It is not an encryption, and it cannot be reversed, therefore the value you have cannot be decrypted.

The only thing you can do with an HMAC is, given the HMAC and the corresponding plain-text, verifying the origin of the plain-text and that it has not been tampered with.

Looking at the GitHub page for the Dart crypto library, it looks like it only supports digest algorithms. There are no encryption algorithms listed, so you will need to use a different library if you want to do two-way encryption which can actually be decrypted. The Cipher library looks like it could be promising in this regard.


PointyCastle (https://pub.dartlang.org/packages/pointycastle) has been recommended in the past, but it appears to have not yet been updated for Dart 2. :(