在安全性要求较高的系统中,建议应使用安全的加密算法(如AES、RSA)对敏感数据进行加密。

    1. BufferedReader bufread2 = null;
    2. InputStreamReader inread2 = null;
    3. try {
    4. inread2 = new InputStreamReader(System.in);
    5. bufread2 = new BufferedReader(inread2);
    6. String str = bufread2.readLine();
    7. /* FIX: Secure cryptographic algorithm (AES) */
    8. Cipher aes = Cipher.getInstance("AES");
    9. KeyGenerator kg = KeyGenerator.getInstance("AES");
    10. kg.init(128);
    11. SecretKey key = kg.generateKey();
    12. aes.init(Cipher.ENCRYPT_MODE, key);
    13. byte[] enc_str = aes.doFinal(str.getBytes());
    14. IO.writeLine(IO.toHex(enc_str));
    15. } catch(IOException e) {
    16. log_gsnk.warning("Error reading from console");
    17. } finally{
    18. ...
    19. }