Bonjour

Je suis un programmeur WinDev et je dois réaliser un programme sous WinDev Mobile.

Pour ce projet je dois installer 3 fichiers .cer.
J'ai trouvé un code sur le net en Java pour pouvoir installer des certificats.

code :
Code : 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.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;
 
public class ImportCa {
 
    public static void m(String[] argv) throws Exception {
 
    String certfile = "/storage/sdcard0/certificat.crt"; /*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();
    }
 
    static private 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 installé Eclipse, puis j'ai suivi un tutoriel pour pouvoir créer des .apk sous Eclispe.

Je crée mon projet certificat avec :
- une classe ImportCa.java=>le code au dessus.
- une classe MainActivity.java et activity_main.xml=> là j'ai mis un bouton et voici le code :
activity_main.xml
Code : 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
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.etib.certificat.MainActivity" >
 
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
 
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginLeft="45dp"
        android:layout_marginTop="33dp"
 
        android:onClick="clickFunc"
 
        android:text="Button" />
 
</RelativeLayout>
MainActivity.java
Code : 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
package com.etib.certificat;
 
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.app.Activity;
import android.view.View;
import android.widget.Toast;
import android.view.View.OnClickListener;
import android.widget.Button;
 
public class MainActivity extends ActionBarActivity {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
 
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
 
    public void clickFunc(View view) throws Exception{
        // Toast.makeText(MainActivity.this, "Button Clicked", Toast.LENGTH_SHORT).show();
        ImportCa.main();
        finish();
                System.exit(0);
    }
}
Mais là, j'ai une erreur sur avec le message est :
the methode main(string[]) in the type ImportCa is not applicable for the arguments()
Je ne sais pas ce que je dois mettre dans les parenthèses.

Quelqu'un saurait-il m'indiquer comment résoudre ce problème ?

Le but de l'application est de s'ouvrir, exécuter la class ImportCa, et puis fermer l'application.

Merci d'avance pour votre aide.