Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Java - utilizzo api di sicurezza in java
Forum - Java - utilizzo api di sicurezza in java

Avatar
albe82 (Normal User)
Newbie


Messaggi: 1
Iscritto: 14/01/2011

Segnala al moderatore
Postato alle 9:02
Venerdì, 14/01/2011
Ciao a tutti...
è la prima volta che scrivo in questo forum.
Ho una richiesta di aiuto da fare....
Devo fare un programmino che mi nasconde una frase (che inserisco "al volo") dentro un'immagine........e fin qui tutto bene....
questo il mio file:


Codice sorgente - presumibilmente Java

  1. package crypto;
  2. import java.awt.image.*;
  3. import java.io.*;
  4. import javax.imageio.ImageIO;
  5.  
  6. public class Encrypt {
  7.     public static void main(String[] args) throws IOException {
  8.         InputStreamReader reader = new InputStreamReader (System.in);
  9. System.out.print("Inserisci il testo da nascondere nell'immagine: \n");
  10. BufferedReader myInput = new BufferedReader (reader);
  11. String msg= new String();
  12. msg = myInput.readLine();
  13.  
  14.         InputStreamReader sreader = new InputStreamReader (System.in);
  15. System.out.print("Inserisci il testo da nascondere nell'immagine: \n");
  16. BufferedReader pathmyInput = new BufferedReader (sreader);
  17. String path= new String();
  18. path = pathmyInput.readLine();
  19.  
  20. File imgFile = new File(path);
  21.         BufferedImage source = null;
  22.         try {
  23.             source = ImageIO.read(imgFile);
  24.         } catch (IOException ex) {
  25.         }
  26.  
  27.         BufferedImage dest = new BufferedImage(source.getWidth(),source.getHeight(),BufferedImage.TYPE_INT_ARGB);
  28.  
  29.         int tmp, pixel, index;
  30.         for(int i=0; i<source.getWidth(); i++) {
  31.             for(int j=0; j<source.getHeight(); j++) {
  32.                 pixel = source.getRGB(i,j);
  33.                 index = (i*source.getHeight())+j;
  34.                 if(index<msg.length()) {
  35.                     tmp = msg.charAt(index);
  36.                     int chan_1 = tmp>>6;
  37.                     int chan_2 = (tmp^(chan_1<<6))>>4;
  38.                     int chan_3 = (tmp^(chan_1<<6)^(chan_2<<4))>>2;
  39.                     int chan_4 = (tmp^(chan_1<<6)^(chan_2<<4)^(chan_3<<2));
  40.                     pixel = pixel^(chan_1<<24)^(chan_2<<16)^(chan_3<<8)^(chan_4);
  41.                 }
  42.                 dest.setRGB(i,j,pixel);
  43.             }
  44.         }
  45.  
  46.         //Salvo l'immagine
  47.         String ext="png";
  48.         imgFile = new File("C:/Users/Alberto/Desktop/Image."+ext);
  49.         try {
  50.             ImageIO.write(dest,ext,imgFile);
  51.         } catch (IOException ex) {
  52.             ex.printStackTrace();
  53.         }
  54.     }
  55. }




alla fine di questo processo ottengo un'immagine di peso superiore alla prima, che contiene il messaggio nascosto.

Ora però voglio prendere l'immagine appena creata, decrittarla, e stampare la frase...

Codice sorgente - presumibilmente Java

  1. package crypto;
  2. import java.awt.image.*;
  3. import java.io.*;
  4. import javax.imageio.ImageIO;
  5.  
  6. public class Decrypt {
  7.  
  8.     public static void main(String[] args) throws IOException {
  9.  
  10.         BufferedImage imgMod = null;
  11.                   File imgFile = new File("C:/Users/Alberto/Desktop/Image.png");
  12.         BufferedImage source = null;
  13.         try {
  14.  source = ImageIO.read(imgFile);
  15.         } catch (IOException ex) {
  16.         }
  17.         try {
  18.            imgMod = ImageIO.read(imgFile);
  19.         } catch (IOException ex) {
  20.         }
  21.         for(int i=0; i<imgMod.getWidth(); i++) {
  22.             for(int j=0; j<imgMod.getHeight(); j++) {
  23.                 int tmp2 = imgMod.getRGB(i,j)^source.getRGB(i,j);
  24.                 int chan_1 = tmp2>>24;
  25.                 int chan_2 = (tmp2^(chan_1<<24))>>16;
  26.                 int chan_3 = (tmp2^(chan_1<<24)^(chan_2<<16))>>8;
  27.                 int chan_4 = (tmp2^(chan_1<<24)^(chan_2<<16)^(chan_3<<8));
  28.                 char c = (char)((chan_1<<6)^(chan_2<<4)^(chan_3<<2)^(chan_4));
  29.                 if(c!=0) {
  30.                   System.out.print(c);
  31.                 }
  32.             }
  33.         }        }        }



il problema è che, quando il file viene compilato, non mi stampa a video NIENTE.
Vuoto.
sapreste dirmi dov'è il problema?

Inoltre vorrei aggiungere dei controlli per la sicurezza....
mi sapreste aiutare?
grazie

PM Quote