Visualizzazione dei risultati da 1 a 1 su 1
  1. #1

    Autenticazione SMTP con password criptata

    Ciao a tutti,
    sto creando una classe per eseguire una autenticazione con un server SMTP.
    Ho creato un metodo che attualmente simula un invio di email. Il metodo è questo:
    codice:
        private static void sendFrom(String from, String pass, String[] to, String subject, String body) {
            Properties props = System.getProperties();
            String host = "smtps.xxxxx.it";
            props.put("mail.smtp.starttls.enable", "false");
            props.put("mail.smtp.ssl.enable", "true");
            props.put("mail.smtp.host", host);
            props.put("mail.smtp.user", from);
            props.put("mail.smtp.password", pass);
            props.put("mail.smtp.port", "465");
            props.put("mail.smtp.auth", "true");
            //props.put("mail.smtp.auth.mechanisms", "CRAM-MD5");
    
            Session session = Session.getDefaultInstance(props);
            MimeMessage message = new MimeMessage(session);
    
            try {
                message.setFrom(new InternetAddress(from));
                InternetAddress[] toAddress = new InternetAddress[to.length];
    
                // To get the array of addresses
                for( int i = 0; i < to.length; i++ ) {
                    toAddress[i] = new InternetAddress(to[i]);
                }
    
                for( int i = 0; i < toAddress.length; i++) {
                    message.addRecipient(Message.RecipientType.TO, toAddress[i]);
                }
    
                message.setSubject(subject);
                message.setText(body);
                Transport transport = session.getTransport("smtps");
                transport.connect(host, from, pass);
                transport.sendMessage(message, message.getAllRecipients());
                transport.close();
                
                System.out.println("Email inviata correttamente");
            }
            catch (AddressException ae) {
                ae.printStackTrace();
            }
            catch (MessagingException me) {
                me.printStackTrace();
            }
        }
    Quello che ora mi serve, per rendere l'applicativo che userà questo sicuro, è evitare di passargli la password in chiaro ma criptarla (magari con l'algoritmo Digest MD5) per poi passarla al metodo (e di conseguenza a connect).
    Ho provato a cercare su internet una soluzione in tal senso ma non ho trovato proprio nulla.

    Qualcuno ha una soluzione?
    Ultima modifica di LeleFT; 11-11-2015 a 16:58 Motivo: Modificati tag PHP con tag CODE
    Troppo difficile cambiare, essere normale!!


    JoomlaPost

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.