如何在 Dart 中使用 PKCS5 填充密钥生成 256-AES CBC 密钥

How to generate 256-AES CBC key with PKCS5 padding key in Dart

我需要弄清楚如何在 Dart 中为我的 Flutter 项目生成带有 PKCS5 填充的随机 256 AES CBC 密钥。我已经能够在 Java 中使用此方法完成它:

    public static SecretKey generateSecretKey() {
        KeyGenerator generator;
        try {
            generator = KeyGenerator.getInstance("AES/CBC/PKCS5Padding");
            generator.init(256); // The AES key size in number of bits (256)

            return generator.generateKey();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }

在 dart 中,我已经使用 PointyCastle

做到了这一点(broken/unfinished 代码)
  static generateSecretKey() {
    AESFastEngine aes = AESFastEngine();
    KeyParameter keyParameter = KeyParameter();
    aes.init(true, keyParameter);
    CBCBlockCipher cbc = CBCBlockCipher(aes);
  }

我使用 RSA 4096 密钥交换 AES 256 密钥。在客户端,我只使用 public 密钥来加密生成的 AES 密钥

@James Reinstate Monica Polk

Apparently dart provides this for you: https://www.scottbrady91.com/Dart/Generating-a-Crypto-Random-String-in-Dart

这似乎是生成 AES 256 位密钥的好解决方案。