Salut à tous,

Bon ce n'est pas dans mes habitudes de débarquer sur un forum et de demander de l'aide mais là je n'y comprends rien, j'ai des notions en PHP etc mais en JAVA rien du tout...

Voilà j'ai besoin de faire fonctionner un script...
Voici ce que contiens le fichier *.bat qui lance le script :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
@java -cp .;log4j-1.2.15.jar;tis2web.jar  KeyGen %1 %2
Et ce que contient le fichier *.class :
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
import com.eoos.gm.tis2web.registration.service.cai.AuthorizationStatus;
import com.eoos.gm.tis2web.registration.service.cai.InstallationType;
import com.eoos.gm.tis2web.registration.standalone.authorization.License;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.util.*;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import org.apache.log4j.*;
 
public class KeyGen
{
 
    private static InstallationType installationType;
    private static final Logger log = Logger.getLogger(com/eoos/gm/tis2web/registration/standalone/authorization/License);
    public static boolean CHECKMODE;
    private static String hardwareHashID;
    private static String hardwareID;
    private static int users;
    private static String authorizationID;
    private static AuthorizationStatus authorizationStatus;
    private static String subscriberID;
    private static long timestamp;
    private static byte timestamp1[];
    private static Random random = new Random();
 
    public KeyGen()
    {
    }
 
    public static void main(String args[])
        throws Exception
    {
        ConsoleAppender appender = new ConsoleAppender(new PatternLayout());
        log.addAppender(appender);
        if(args.length > 0)
        {
            setSubscriberID("TIS2WEB");
            byte key[] = keyAES("TIS2WEB");
            decode(decryptAES(key, toBytes(args[0])));
            authorize();
            if(args.length > 1)
            {
                setSubscriberID(args[1]);
            } else
            {
                int rnd = Math.abs(random.nextInt(0x3b9ac9ff));
                DecimalFormat df2 = new DecimalFormat("000000000");
                setSubscriberID((new StringBuilder("T")).append(df2.format(rnd)).toString());
            }
            System.out.println(getSubscriberID());
            System.out.println(encrypt(encode()));
        } else
        {
            System.out.println("Enter request key");
        }
        System.out.println("     Scarymistake       ");
        System.exit(0);
    }
 
    private static byte[] keyAES(String key)
    {
        byte buffer[] = (byte[])null;
        try
        {
            buffer = (new StringBuilder()).append("##").append(pad(key, 10)).append("####").toString().getBytes("US-ASCII");
        }
        catch(UnsupportedEncodingException e)
        {
            log.error("getBytes() failed", e);
            buffer = (new StringBuilder()).append("##").append(pad(key, 10)).append("####").toString().getBytes();
        }
        return buffer;
    }
 
    private static String pad(String value, int length)
    {
        if(value == null)
        {
            value = "";
        }
        StringBuffer buffer = new StringBuffer();
        buffer.append(value);
        for(; buffer.length() < length; buffer.append('~')) { }
        return buffer.toString().substring(0, length);
    }
 
    public static byte[] toBytes(String hex)
    {
        byte bytes[] = new byte[hex.length() / 2];
        for(int i = 0; i < hex.length() / 2; i++)
        {
            bytes[i] = (byte)Integer.parseInt(hex.substring(i * 2, i * 2 + 2), 16);
        }
 
        return bytes;
    }
 
    private static byte[] decryptAES(byte key[], byte encryption[])
        throws Exception
    {
        SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(2, skeySpec);
        return cipher.doFinal(encryption);
    }
 
    public static String bytesToHex(boolean format, byte data[], int length)
    {
        StringBuffer buffer = new StringBuffer();
        for(int i = 0; i < length; i++)
        {
            buffer.append(toHex(data[i]));
            if(format && (i + 1) % 2 == 0 && i < length - 1)
            {
                buffer.append("-");
            }
        }
 
        return buffer.toString().toUpperCase(Locale.ENGLISH);
    }
 
    public static String toHex(byte b)
    {
        Integer I = new Integer((b << 24) >>> 24);
        int i = I.intValue();
        if(i < 16)
        {
            return (new StringBuilder()).append("0").append(Integer.toString(i, 16)).toString();
        } else
        {
            return Integer.toString(i, 16);
        }
    }
 
    public static String bytesToHex(byte data[])
    {
        return bytesToHex(true, data, data.length);
    }
 
    private static void decode(byte payload[])
    {
        if(payload[23] != 0)
        {
            return;
        }
        if(payload[24] != checksum(payload, 0, 22))
        {
            return;
        }
        if(payload[25] != (byte)(checksum(payload, 0, 30) - payload[25]))
        {
            return;
        } else
        {
            byte hwid[] = new byte[10];
            copy(hwid, 0, payload);
            hardwareHashID = new String(hwid);
            installationType = InstallationType.get(payload[10]);
            users = payload[11];
            authorizationStatus = AuthorizationStatus.get(payload[12]);
            byte subscription[] = new byte[10];
            transfer(subscription, 13, payload);
            String subscriptionID = new String(subscription);
            authorizationID = subscriptionID.replace('~', ' ').trim();
            byte ts[] = new byte[5];
            transfer(ts, 26, payload);
            timestamp1 = new byte[5];
            transfer(timestamp1, 26, payload);
            timestamp = Long.parseLong(new String(ts));
            return;
        }
    }
 
    private static byte checksum(byte data[], int start, int stop)
    {
        int sum = 0;
        for(int i = start; i <= stop; i++)
        {
            sum += data[i];
        }
 
        return (byte)(sum % 255);
    }
 
    private static void copy(byte target[], int start, byte source[])
    {
        int i = start;
        for(int j = 0; j < source.length && i < target.length; j++)
        {
            target[i] = source[j];
            i++;
        }
 
    }
 
    private static void transfer(byte target[], int start, byte source[])
    {
        int i = start;
        for(int j = 0; i < source.length && j < target.length; j++)
        {
            target[j] = source[i];
            i++;
        }
 
    }
 
    private static byte[] encode()
    {
        byte payload[] = new byte[31];
        try
        {
            copy(payload, 0, getHardwareHashID().getBytes("US-ASCII"));
        }
        catch(UnsupportedEncodingException e)
        {
            log.error("getBytes() failed", e);
            copy(payload, 0, getHardwareHashID().getBytes());
        }
        payload[10] = (byte)getInstallationType().ord();
        payload[11] = (byte)getUsers();
        payload[12] = (byte)getAuthorizationStatus().ord();
        try
        {
            copy(payload, 13, pad(getAuthorizationID(), 10).getBytes("US-ASCII"));
        }
        catch(UnsupportedEncodingException e)
        {
            log.error("getBytes() failed", e);
            copy(payload, 13, pad(getAuthorizationID(), 10).getBytes());
        }
        copy(payload, 26, timestamp1);
        payload[24] = checksum(payload, 0, 22);
        payload[25] = checksum(payload, 0, 30);
        return payload;
    }
 
    private static String seconds(long timestamp)
    {
        Calendar date = Calendar.getInstance();
        date.setTimeInMillis(timestamp);
        int seconds = date.get(13) + date.get(12) * 60 + date.get(10) * 60 * 60;
        return pad(seconds, 5);
    }
 
    private static String pad(int value, int length)
    {
        String data = Integer.toString(value);
        if(data.length() < length)
        {
            StringBuffer padding;
            for(padding = new StringBuffer(); padding.length() < length - data.length(); padding.append('0')) { }
            data = (new StringBuilder()).append(padding).append(data).toString();
        }
        return data;
    }
 
    public static String getAuthorizationID()
    {
        return authorizationID;
    }
 
    public static void setAuthorizationID(String authorizationID1)
    {
        authorizationID = authorizationID1;
    }
 
    public static AuthorizationStatus getAuthorizationStatus()
    {
        return authorizationStatus;
    }
 
    public static String getHardwareHashID()
    {
        return hardwareHashID;
    }
 
    public static String getHardwareID()
    {
        return hardwareID;
    }
 
    public static int getUsers()
    {
        return users;
    }
 
    public static InstallationType getInstallationType()
    {
        return installationType;
    }
 
    private static String encrypt(byte payload[])
        throws Exception
    {
        byte key[] = keyAES(getSubscriberID());
        return bytesToHex(encryptAES(key, payload));
    }
 
    public static String getSubscriberID()
    {
        return subscriberID;
    }
 
    private static byte[] encryptAES(byte key[], byte payload[])
        throws Exception
    {
        SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(1, skeySpec);
        byte encrypted[] = cipher.doFinal(payload);
        return encrypted;
    }
 
    public static void setSubscriberID(String subscriberID1)
    {
        subscriberID = subscriberID1.toUpperCase(Locale.ENGLISH);
    }
 
    public static void authorize()
    {
        authorizationStatus = AuthorizationStatus.AUTHORIZED;
    }
 
    public static long getTimestamp()
    {
        return timestamp;
    }
 
}
EDIT :
Et enfin l'erreur que j'ai avec Java 6 (ce code a du être écrit avec normalement) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
Exception in thread "main" javax.crypto.BadPaddingException: Given final block not properly padded
        at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..)
        at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..)
        at com.sun.crypto.provider.AESCipher.engineDoFinal(DashoA13*..)
        at javax.crypto.Cipher.doFinal(DashoA13*..)
        at KeyGen.decryptAES(KeyGen.java:102)
        at KeyGen.main(KeyGen.java:44)
La même erreur en tournant avec Java 8 :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
Exception in thread "main" javax.crypto.BadPaddingException: Given final block not properly padded
        at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:966)
        at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:824)
        at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:436)
        at javax.crypto.Cipher.doFinal(Cipher.java:2165)
        at KeyGen.decryptAES(KeyGen.java:102)
        at KeyGen.main(KeyGen.java:44)
Si l'un d'entre vous pourrait m'aider, ce serait trop gentil, merci d'avance !