@Override
    public String encode(Password password) throws GeneralSecurityException {
        byte[] salt = new byte[256];
        secureRandom.nextBytes(salt);
        Cipher cipher = Cipher.getInstance(cipherAlgorithm);
        SecretKeyFactory keyFactory = secretKeyFactory(keyFactoryAlgorithm);
        SecretKeySpec keySpec = secretKeySpec(keyFactory, cipherAlgorithm, keyLength, salt, iterations);
        cipher.init(Cipher.ENCRYPT_MODE, keySpec);
        byte[] encryptedPassword = cipher.doFinal(password.value().getBytes(StandardCharsets.UTF_8));
        Map<String, String> encryptedMap = new HashMap<>();
        encryptedMap.put(PasswordEncoder.KEY_FACTORY_ALGORITHM, keyFactory.getAlgorithm());
        encryptedMap.put(PasswordEncoder.CIPHER_ALGORITHM, cipherAlgorithm);
        encryptedMap.put(PasswordEncoder.KEY_LENGTH, String.valueOf(keyLength));
        encryptedMap.put(PasswordEncoder.SALT, PasswordEncoder.base64Encode(salt));
        encryptedMap.put(PasswordEncoder.ITERATIONS, String.valueOf(iterations));
        encryptedMap.put(PasswordEncoder.ENCRYPTED_PASSWORD, PasswordEncoder.base64Encode(encryptedPassword));
        encryptedMap.put(PasswordEncoder.PASSWORD_LENGTH, String.valueOf(password.value().length()));
        encryptedMap.putAll(cipherParamsEncoder.toMap(cipher.getParameters()));

        return encryptedMap.entrySet().stream()
                .map(entry -> entry.getKey() + ":" + entry.getValue())
                .collect(Collectors.joining(","));
    }
@param secret The secret used for encoding and decoding
@param keyFactoryAlgorithm  Key factory algorithm if configured. By default, PBKDF2WithHmacSHA512 is
                            used if available, PBKDF2WithHmacSHA1 otherwise.
@param cipherAlgorithm Cipher algorithm used for encoding.
@param keyLength Key length used for encoding. This should be valid for the specified algorithms.
@param iterations Iteration count used for encoding.
The provided `keyFactoryAlgorithm`, `cipherAlgorithm`, `keyLength` and `iterations` are used for encoding passwords.
The values used for encoding are stored along with the encoded password and the stored values are used for decoding.
server-common/src/main/java/org/apache/kafka/security/EncryptingPasswordEncoder.java