IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windev Mobile Discussion :

Transformer une classe java dans une procédure global de type java


Sujet :

Windev Mobile

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    325
    Détails du profil
    Informations personnelles :
    Localisation : France, Morbihan (Bretagne)

    Informations forums :
    Inscription : Mars 2008
    Messages : 325
    Points : 150
    Points
    150
    Par défaut Transformer une classe java dans une procédure global de type java
    Bonjour

    J'utilise windev mobile. J'aimerais installer un certificat automatiquement sur ma tablette.
    j'ai trouvé le code suivant :
    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.security.Key;
    import java.security.KeyStore;
    import java.security.cert.Certificate;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.DataInputStream;
    import java.io.ByteArrayInputStream;
    import java.security.spec.*;
    import java.security.cert.Certificate;
    import java.security.cert.CertificateFactory;
    import java.util.Collection;
     
    public class InstallCertificat {
    	public static void main(String[] argv) throws Exception {
     
    		String certfile = "yourcert.cer"; /*your cert path*/
    		FileInputStream is = new FileInputStream("yourKeyStore.keystore");
     
    		KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    		keystore.load(is, "yourKeyStorePass".toCharArray());
     
    		String alias = "youralias";
    		char[] password = "yourKeyStorePass".toCharArray();
     
    		//////
     
    		CertificateFactory cf = CertificateFactory.getInstance("X.509");
    		InputStream certstream = fullStream (certfile);
    		Certificate certs =  cf.generateCertificate(certstream);
     
    		///
    		File keystoreFile = new File("yourKeyStorePass.keystore");
    		// Load the keystore contents
    		FileInputStream in = new FileInputStream(keystoreFile);
    		keystore.load(in, password);
    		in.close();
     
    		// Add the certificate
    		keystore.setCertificateEntry(alias, certs);
     
    		// Save the new keystore contents
    		FileOutputStream out = new FileOutputStream(keystoreFile);
    		keystore.store(out, password);
    		out.close();
     
    	}
     
    	private static InputStream fullStream ( String fname ) throws IOException {
    		FileInputStream fis = new FileInputStream(fname);
    		DataInputStream dis = new DataInputStream(fis);
    		byte[] bytes = new byte[dis.available()];
    		dis.readFully(bytes);
    		ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    		return bais;
    	}
    }

    J'aimerai le tester sur mon projet.
    1 - création d'une collection de procédure globale :"COL_CERTIFICAT"
    puis création de deux procédures

    java Procédure globale main :
    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.security.Key;
    import java.security.KeyStore;
    import java.security.cert.Certificate;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.DataInputStream;
    import java.io.ByteArrayInputStream;
    import java.security.spec.*;
    import java.security.cert.Certificate;
    import java.security.cert.CertificateFactory;
    import java.util.Collection;
     
     
    public static void main(String[] argv) throws Exception 
    {
     
    	String certfile = "certificat.cer"; /*your cert path*/
    	FileInputStream is = new FileInputStream("yourKeyStore.keystore");
     
    	KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    	keystore.load(is, "yourKeyStorePass".toCharArray());
     
    	String alias = "youralias";
    	char[] password = "yourKeyStorePass".toCharArray();
     
    	//////
     
    	CertificateFactory cf = CertificateFactory.getInstance("X.509");
    	InputStream certstream = fullStream (certfile);
    	Certificate certs =  cf.generateCertificate(certstream);
     
    	///
    	File keystoreFile = new File("yourKeyStorePass.keystore");
    	// Load the keystore contents
    	FileInputStream in = new FileInputStream(keystoreFile);
    	keystore.load(in, password);
    	in.close();
     
    	// Add the certificate
    	keystore.setCertificateEntry(alias, certs);
     
    	// Save the new keystore contents
    	FileOutputStream out = new FileOutputStream(keystoreFile);
    	keystore.store(out, password);
    	out.close();
     
    }

    puis java Procédure globale InputStream
    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    private static InputStream fullStream ( String fname ) throws IOException {
    	FileInputStream fis = new FileInputStream(fname);
    	DataInputStream dis = new DataInputStream(fis);
    	byte[] bytes = new byte[dis.available()];
    	dis.readFully(bytes);
    	ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    	return bais;
    }

    J'ai la première ligne en vert pour les deux procédures. Type de retour non valide et type du paramètre non valide des warning en bleu

    et si je génère j'ai une fenêtre Echec de la génération :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    Echec de la création de l'application Android <K:\eol18\PEC_TIRAT\Exe\Application Android\PecEol.apk>.
     
     
    Ligne de commande : "C:\Program Files (x86)\Java\jdk1.7.0\bin\javac.exe" -encoding UTF-16LE -nowarn -source 1.5 -target 1.5 -d bin\classes -bootclasspath "C:\sdkandroid\platforms\android-10\android.jar" gen\fr\etib\peceol\*.java src\fr\etib\peceol\wdgen\*.java -classpath "libs;libs\android-support-v4.jar"
     
     
    Erreur retournée :
    src\fr\etib\peceol\wdgen\GWDFFEN_Requete.java:3115: error: method main in class GWDCPCOL_Certificat cannot be applied to given types;
    GWDCPCOL_Certificat.main();
                       ^
      required: String[]
      found: no arguments
      reason: actual and formal argument lists differ in length
    1 error
    que dois-je faire?

    cordialement Law56100
    je connais que le langague windev, j'avoue je ne comprends pas grand chose en java

  2. #2
    Membre habitué
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    325
    Détails du profil
    Informations personnelles :
    Localisation : France, Morbihan (Bretagne)

    Informations forums :
    Inscription : Mars 2008
    Messages : 325
    Points : 150
    Points
    150
    Par défaut
    Voici le code que j'ai réalisé :

    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.security.Key;
    import java.security.KeyStore;
    import java.security.cert.Certificate;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.DataInputStream;
    import java.io.ByteArrayInputStream;
    import java.security.spec.*;
    import java.security.cert.Certificate;
    import java.security.cert.CertificateFactory;
    import java.util.Collection;
     
    public static void main() 
    {
    	try {
    		String certfile = "/storage/sdcard0/certificat.crt"; 
     
    		FileInputStream is = new FileInputStream("mon.keystore");
     
    		KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    		keystore.load(is, "password".toCharArray());
     
    		String alias = "monalias";
    		char[] password = "password".toCharArray();
     
    		//////
     
    		CertificateFactory cf = CertificateFactory.getInstance("X.509");
    		FileInputStream certstream = new FileInputStream(certfile);
    		Certificate certs =  cf.generateCertificate(certstream);
     
    		///
    		File keystoreFile = new File("mon.keystore");
    		// Load the keystore contents
    		FileInputStream in = new FileInputStream(keystoreFile);
    		keystore.load(in, password);
    		in.close();
     
    		// Add the certificate
    		keystore.setCertificateEntry(alias, certs);
     
    		// Save the new keystore contents
    		FileOutputStream out = new FileOutputStream(keystoreFile);
    		keystore.store(out, password);
    		out.close();
     
    	} 
    	catch (Exception e) 
    	{
    		e.printStackTrace();
    	}
    }

    Lorsque j'exécute le code, il ne plante pas mais le certificat n'est pas installé?
    Je ne sais pas si c'est bien ça que je dois faire.

    Cordialement Law56100

Discussions similaires

  1. Appel d'une méthode d'une classe A dans une classe B
    Par halloumiali dans le forum Général Java
    Réponses: 1
    Dernier message: 16/04/2012, 00h30
  2. Réponses: 7
    Dernier message: 05/04/2011, 17h19
  3. Réponses: 21
    Dernier message: 14/01/2010, 12h50
  4. Réponses: 15
    Dernier message: 28/04/2009, 07h26
  5. Réponses: 6
    Dernier message: 30/03/2009, 18h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo