Visualizzazione dei risultati da 1 a 6 su 6
  1. #1
    Utente di HTML.it
    Registrato dal
    Aug 2008
    Messaggi
    94

    Non viene trovato il main

    Salve a tutti. Ho trovato questa classe su internet che mi servirebbe come base da cui partire. Volevo però prima provare a farla girare per vedere al dettaglio l'output, ma quando faccio per lanciarla ottengo questo errore : "Selection does not contain a main type"

    Come mai? dove sta l'errore? Vi posto la classe :

    Codice PHP:
    import java.security.*;
       
    import javax.crypto.*;
       
    import javax.crypto.spec.*;
    import java.io.*;

       
    /**
       * This program generates a AES key, retrieves its raw bytes, and
       * then reinstantiates a AES key from the key bytes.
       * The reinstantiated key is used to initialize a AES cipher for
       * encryption and decryption.
       */

       
    public class AES {

         
    /**
         * Turns array of bytes into string
         *
         * @param buf    Array of bytes to convert to hex string
         * @return    Generated hex string
         */
         
    public static void main(String[] argsthrows Exception {

           
    String message="This is just an example";

           
    // Get the KeyGenerator

           
    KeyGenerator kgen KeyGenerator.getInstance("AES");
           
    kgen.init(128); // 192 and 256 bits may not be available


           // Generate the secret key specs.
           
    SecretKey skey kgen.generateKey();
           
    byte[] raw skey.getEncoded();

           
    SecretKeySpec skeySpec = new SecretKeySpec(raw"AES");


           
    // Instantiate the cipher

           
    Cipher cipher Cipher.getInstance("AES");

           
    cipher.init(Cipher.ENCRYPT_MODEskeySpec);

           
    byte[] encrypted =
             
    cipher.doFinal((args.length == ?
              
    "This is just an example" args[0]).getBytes());
           
    System.out.println("encrypted string: " asHex(encrypted));

           
    cipher.init(Cipher.DECRYPT_MODEskeySpec);
           
    byte[] original =
             
    cipher.doFinal(encrypted);
           
    String originalString = new String(original);
           
    System.out.println("Original string: " +
             
    originalString " " asHex(original));
         }
         
         public static 
    String asHex (byte buf[]) {
             
    StringBuffer strbuf = new StringBuffer(buf.length 2);
             
    int i;

             for (
    0buf.lengthi++) {
              if (((int) 
    buf[i] & 0xff) < 0x10)
               
    strbuf.append("0");

              
    strbuf.append(Long.toString((int) buf[i] & 0xff16));
             }

             return 
    strbuf.toString();
            }

       } 
    Grazie

  2. #2
    Utente di HTML.it
    Registrato dal
    Jan 2010
    Messaggi
    17
    Ho provato a farlo girare su Eclipse e gira...

  3. #3
    Utente di HTML.it
    Registrato dal
    Aug 2008
    Messaggi
    94
    Ma hai creato una java configuration nuova?

    sennò ci metti meno a dirmi come hai fatto per farlo girare

  4. #4
    Utente di HTML.it
    Registrato dal
    Feb 2009
    Messaggi
    502
    Originariamente inviato da brouls
    Ma hai creato una java configuration nuova?

    sennò ci metti meno a dirmi come hai fatto per farlo girare
    Se la tua classe che contiene il main ha lo stesso nome del file .java
    Se il ClassPath è corretto.
    Non dovresti avere problemi.
    al volante son nervoso

  5. #5
    Utente di HTML.it
    Registrato dal
    Aug 2008
    Messaggi
    94
    risolto, avevo fatto un piccolo errore io

    ho però un'altra domanda di altro genere :

    ho bisogno di una stringa random di 16 byte che vada bene per una codifica in base64.

    ho provato queste 3 :

    1234567801gAES12
    1234567801gAES12=
    1234567801gAES1=

    ma ottengo sempre questo errore : IV not 16 bytes long (dove IV è la mia stringa)...dove sbaglio?

    grazie

  6. #6
    Utente di HTML.it
    Registrato dal
    Aug 2008
    Messaggi
    94
    Praticamente quello che mi serve è una stringa di 16 byte fatta con i caratteri validi per il base64

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.