程序应采用不小于8个字节的随机生成的字符串作为密匙。

    1. KeyGenerator keyGen = KeyGenerator.getInstance("AES");
    2. keyGen.init(128, new SecureRandom(password.getBytes()));
    3. SecretKey secretKey = kgen.generateKey();
    4. byte[] keyBytes = secretKey.getEncoded();
    5. SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
    6. Cipher encryptCipher = Cipher.getInstance("AES");
    7. encryptCipher.init(Cipher.ENCRYPT_MODE, key);