decrypt AES input on Flutter, when on web use cryptoJS AES

flutter aes encryption
pointycastle
flutter end-to-end encryption
flutter crypto
flutter scrypt
flutter md5
flutter pub global activate encrypt
encrypt 3.3 1

On web, I'm using CryptoJS for decrypto JS:

CryptoJS.AES.decrypt(inputBase64, key).toString(CryptoJS.enc.Utf8);

Example:

input: "tzfwnxVwE/qNoaWRRfqLp11ZyhB4UtKO+0/Lvv5B7eE=" key: "20190225165436_15230006321670000_15510884759030000"

On flutter I can't find any library to decrypt with a key of any length.

I know "For AES, NIST selected three members of the Rijndael family, each with a block size of 128 bits, but three different key lengths: 128, 192 and 256 bits. "

But I don't know how to convert any length key to 128 bit format?

encryption, On web, I'm using CryptoJS for decrypto JS: CryptoJS.AES.decrypt(inputBase64, key).toString(CryptoJS.enc.Utf8);. Example: input:� I am trying to write two function in flutter and Javascript which I can use throughout my project to encrypt or decrypt data using AES when data is exchanged. For Flutter I am using the pointycastle package based on instructions [login to view URL] For the Javascript solution I am using CryptoJS. var AESKey = "20190225165436_15230006321670000"

Sample encrypt using nodejs script:
var key = CryptoJS.PBKDF2("123456", "123456", {
  keySize: 256 / 32
});
var iv = CryptoJS.PBKDF2("123456", "123456", {
  keySize: 128 / 32
});

var encrypted = CryptoJS.AES.encrypt('my message', key, { iv: iv,
  mode: CryptoJS.mode.CBC,
  padding: CryptoJS.pad.Pkcs7
}).toString();

decript using dart


import 'package:encrypt/encrypt.dart' as aes;
import 'package:crypto/crypto.dart';
import 'package:hex/hex.dart';
import 'package:password_hash/pbkdf2.dart';

void main(List<String> arguments) {
  String encrypted = 'HbsmGAigiIWmU3MNZAf8+w==';

  final generator = PBKDF2(hashAlgorithm: sha1);
  final key = aes.Key.fromBase16(HEX.encode(generator.generateKey("123456", "123456", 1, 32)));
  final iv = aes.IV.fromBase16(HEX.encode(generator.generateKey("123456", "123456", 1, 16)));

  final encrypter = aes.Encrypter(aes.AES(key, mode: aes.AESMode.cbc, padding: 'PKCS7'));

  final decrypted = encrypter.decrypt64(encrypted, iv:iv);
  print(decrypted);
}

CryptoJS AES Encryption/Decryption For Flutter/Dart, If you using CryptoJS below AES encryption for your website/react native and you need it for flutter app or dart web application var CryptoJS� I want to create two functions encrypt(message, key) and decrypt(ciphertext, key) using the Forge library in javascript, but I dont undestand the example code.

import 'dart:convert';
import 'dart:math';
import 'dart:typed_data';
import 'package:crypto/crypto.dart';
import 'package:tuple/tuple.dart';
import 'package:encrypt/encrypt.dart' as encrypt;

String encryptAESCryptoJS(String plainText, String passphrase) {
try {
    final salt = genRandomWithNonZero(8);
    var keyndIV = deriveKeyAndIV(passphrase, salt);
    final key = encrypt.Key(keyndIV.item1);
    final iv = encrypt.IV(keyndIV.item2);

    final encrypter = encrypt.Encrypter(
        encrypt.AES(key, mode: encrypt.AESMode.cbc, padding: "PKCS7"));
    final encrypted = encrypter.encrypt(plainText, iv: iv);
    Uint8List encryptedBytesWithSalt = Uint8List.fromList(
        createUint8ListFromString("Salted__") + salt + encrypted.bytes);
    return base64.encode(encryptedBytesWithSalt);
} catch (error) {
    throw error;
}
}

String decryptAESCryptoJS(String encrypted, String passphrase) {
try {
    Uint8List encryptedBytesWithSalt = base64.decode(encrypted);

    Uint8List encryptedBytes =
        encryptedBytesWithSalt.sublist(16, encryptedBytesWithSalt.length);
    final salt = encryptedBytesWithSalt.sublist(8, 16);
    var keyndIV = deriveKeyAndIV(passphrase, salt);
    final key = encrypt.Key(keyndIV.item1);
    final iv = encrypt.IV(keyndIV.item2);

    final encrypter = encrypt.Encrypter(
        encrypt.AES(key, mode: encrypt.AESMode.cbc, padding: "PKCS7"));
    final decrypted =
        encrypter.decrypt64(base64.encode(encryptedBytes), iv: iv);
    return decrypted;
} catch (error) {
    throw error;
}
}

Tuple2<Uint8List, Uint8List> deriveKeyAndIV(String passphrase, Uint8List salt) {
var password = createUint8ListFromString(passphrase);
Uint8List concatenatedHashes = Uint8List(0);
Uint8List currentHash = Uint8List(0);
bool enoughBytesForKey = false;
Uint8List preHash = Uint8List(0);

while (!enoughBytesForKey) {
    int preHashLength = currentHash.length + password.length + salt.length;
    if (currentHash.length > 0)
    preHash = Uint8List.fromList(
        currentHash + password + salt);
    else
    preHash = Uint8List.fromList(
        password + salt);

    currentHash = md5.convert(preHash).bytes;
    concatenatedHashes = Uint8List.fromList(concatenatedHashes + currentHash);
    if (concatenatedHashes.length >= 48) enoughBytesForKey = true;
}

var keyBtyes = concatenatedHashes.sublist(0, 32);
var ivBtyes = concatenatedHashes.sublist(32, 48);
return new Tuple2(keyBtyes, ivBtyes);
}

Uint8List createUint8ListFromString(String s) {
var ret = new Uint8List(s.length);
for (var i = 0; i < s.length; i++) {
    ret[i] = s.codeUnitAt(i);
}
return ret;
}

Uint8List genRandomWithNonZero(int seedLength) {
final random = Random.secure();
const int randomMax = 245;
final Uint8List uint8list = Uint8List(seedLength);
for (int i=0; i < seedLength; i++) {
    uint8list[i] = random.nextInt(randomMax)+1;
}
return uint8list;
}

Usage

import 'package:app/utils/cryptojs_aes_encryption_helper.dart'; String plainText = 'PlainText is Me'; var encrypted = encryptAESCryptoJS(plainText, "password"); var decrypted = decryptAESCryptoJS(encrypted, "password");

How to AES-256 (CBC/CFB mode) encrypt and decrypt in Dart , How to AES-256 (CBC/CFB mode) encrypt and decrypt in Dart/Flutter with Pointy Castle AES key size. const KEY_SIZE = 32; // 32 byte key for AES-256 static String decrypt(String password, String ciphertext,. {String mode Can you help me, fix and run the same input as above? On the web client I use CryptoJS. Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

AES Encryption in dart 2, _processBlocks (package:encrypt/src/aes.dart:42:25) E/flutter (19551): #2 If you using CryptoJS below AES encryption for your website/react native and you CryptoJS AES Encryption/Decryption For Flutter/Dart, Can you help me, in dart language , i tried to use a package but it shows that my input buffer is too short. CryptoJS.AES.encrypt( CryptoJS.enc.Utf8.parse(txtMsg), AESKey, { mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 } ).toString() i use CryptoJS on de/ecript message Looks like the pad and pading process is different with the CryptoJS library

CryptoJS, Original documentation: https://code.google.com/archive/p/crypto-js/ The Hashing Input. The hash algorithms AES.decrypt(encrypted, "Secret Passphrase");. AES encryption and decryption online tool for free.It is an aes calculator that performs aes encryption and decryption of image, text and .txt file in ECB and CBC mode with 128, 192,256 bit. The output can be base64 or Hex encoded.

Encrypt and decrypt react, AES encryption is a web tool to encrypt and decrypt text using AES encryption algorithm. How to AES-256 (CBC/CFB mode) encrypt and decrypt in Dart/ Flutter with data, simply use encrypt() and decrypt() function from an instance of crypto-js. I am able to encrypt input text using a key, but not able to decrypt text using� This is a sample of AES encryption + decryption using CryptoJS. This is a bit different from the examples out there because this one uses a COMPANY header + payload. There's a little bit more processing going on. I also used a CDN for CryptoJS. I hope someone finds this useful.

Comments
  • Possible duplicate of How is an AES key processed when calling CryptoJS.AES.encrypt/decrypt with a non-standard key length?
  • Please refer to below post for solution stackoverflow.com/a/60648119/13049237