dartflutterblowfishcbc-mode

Dart/Flutter Blowfish CBC


How to do Blowfish CBC decryption in Flutter/Dart? I can't find any libraries that support it.

dbcrypt supports only password hashing and no cbc mode.

Thank you.


Solution

  • import 'package:encrypt/encrypt.dart' as encrypt;
    import 'package:encrypt/encrypt.dart';
    
    class _MyHomePageState extends State<MyHomePage> {
    
        final plainText = 'some plain text here';
        final key = encrypt.Key.fromUtf8('16 characters key');
        final iv = IV.fromLength(16);
        final encrypter = Encrypter(AES(key,mode: AESMode.cbc,padding: 'PKCS7'));
        final encrypted = encrypter.encrypt(plainText, iv: iv);
        final decrypted = encrypter.decrypt(encrypted, iv: iv);
        print(decrypted); 
        print(encrypted.base64);
    

    pubspec.yaml:

    
    dependencies:
    
      encrypt: ^4.0.0