Bonjour,

j'ai un petit problème de cryptage en Triple DES: les données que je crypte reste toujours les même qu'avant le cryptage. :

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
 
 
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
 
public class IbsEncrypt
{
	private String Msgid="";
	private String Nucar="";
	private String Court="";
	private String Finval="";
	private String Cvx2="";
	private String Cmc7="";
 
	private String key1="11111111111111111111111111111111";
	private String key2="22222222222222222222222222222222";
	private String key3="33333333333333333333333333333333";
 
 
	/**
         * @param msgid
         * @param nucar
         * @param court
         * @param finval
         * @param cvx2
         * @param cmc7
         */
	public IbsEncrypt(String msgid, String nucar, String court, String finval, String cvx2, String cmc7) {
		Msgid = msgid;
		Nucar = nucar;
		Court = court;
		Finval = finval;
		Cvx2 = cvx2;
		Cmc7 = cmc7;
	}
 
	/**
         * @return the cmc7
         */
	public String getCmc7() {
		return Cmc7;
	}
	/**
         * @param cmc7 the cmc7 to set
         */
	public void setCmc7(String cmc7) {
		Cmc7 = cmc7;
	}
	/**
         * @return the court
         */
	public String getCourt() {
		return Court;
	}
	/**
         * @param court the court to set
         */
	public void setCourt(String court) {
		Court = court;
	}
	/**
         * @return the cvx2
         */
	public String getCvx2() {
		return Cvx2;
	}
	/**
         * @param cvx2 the cvx2 to set
         */
	public void setCvx2(String cvx2) {
		Cvx2 = cvx2;
	}
	/**
         * @return the finval
         */
	public String getFinval() {
		return Finval;
	}
	/**
         * @param finval the finval to set
         */
	public void setFinval(String finval) {
		Finval = finval;
	}
	/**
         * @return the msgid
         */
	public String getMsgid() {
		return Msgid;
	}
	/**
         * @param msgid the msgid to set
         */
	public void setMsgid(String msgid) {
		Msgid = msgid;
	}
	/**
         * @return the nucar
         */
	public String getNucar() {
		return Nucar;
	}
	/**
         * @param nucar the nucar to set
         */
	public void setNucar(String nucar) {
		Nucar = nucar;
	}
 
	/**
         * @return the key1
         */
	public String getKey1() {
		return key1;
	}
 
	/**
         * @param key1 the key1 to set
         */
	public void setKey1(String key1) {
		this.key1 = key1;
	}
 
	/**
         * @return the key2
         */
	public String getKey2() {
		return key2;
	}
 
	/**
         * @param key2 the key2 to set
         */
	public void setKey2(String key2) {
		this.key2 = key2;
	}
 
	/**
         * @return the key3
         */
	public String getKey3() {
		return key3;
	}
 
	/**
         * @param key3 the key3 to set
         */
	public void setKey3(String key3) {
		this.key3 = key3;
	}
 
	public String getIbsClair()
	{
		String ibsClair="<Msgid>"+Msgid+"</Msgid>";
		ibsClair+="<Nucar>"+Nucar+"</Nucar>";
		ibsClair+="<Court>"+Court+"</Court>";
		ibsClair+="<Finval>"+Finval+"</Finval>";
		ibsClair+="<Cvx2>"+Cvx2+"</Cvx2>";
		ibsClair+="<Cmc7>"+Cmc7+"</Cmc7>";
 
		return ibsClair;
	}
 
	public byte[] getIbsCrypt(int nKey)
	{
		byte[] rawKey;
		switch(nKey)
		{
		case 1:
			System.out.println("clé "+key1);
			rawKey=key1.getBytes();
			break;
		case 2:
			System.out.println("clé "+key2);
			rawKey=key2.getBytes();
			break;
		case 3:
			System.out.println("clé "+key3);
			rawKey=key3.getBytes();
			break;
		case 0:
		default:
			System.out.println("clair");
			return getIbsClair().getBytes();
		}
 
		try{
			SecretKey skeySpec = new SecretKeySpec(rawKey, "DESebe");
			System.out.println("DESebe/CBC/NoPadding");
			Cipher c = Cipher.getInstance("DESebe/CBC/PKCS5Padding", "SunJCE");
			System.out.println("ENCRYPT_MODE");
			c.init(Cipher.ENCRYPT_MODE, skeySpec);
			return c.doFinal(getIbsClair().getBytes());
		}
		catch(Exception e){/*On ne fait rien, Eception théroriquement impossible*/}
 
		return getIbsClair().getBytes();
	}
 
	public byte[] decryptIbs(byte[] cryptMsg,int nKey)
	{
		byte[] rawKey;
		switch(nKey)
		{
		case 1:
			rawKey=key1.getBytes();
			break;
		case 2:
			rawKey=key2.getBytes();
			break;
		case 3:
			rawKey=key3.getBytes();
			break;
		case 0:
		default:
			return getIbsClair().getBytes();
		}
 
		try{
			SecretKey skeySpec = new SecretKeySpec(rawKey, "DESebe");
			Cipher c = Cipher.getInstance("DESebe/CBC/PKCS5Padding", "SunJCE");
			c.init(Cipher.DECRYPT_MODE, skeySpec);
			return c.doFinal(cryptMsg);
		}
		catch(Exception e){/*On ne fait rien, Eception théroriquement impossible*/}
 
		return getIbsClair().getBytes();
	}
 
	public static void main (String[] args)
	{
		IbsEncrypt ibs = new IbsEncrypt("msgid","0123456789123456","","","123","");
		String msg = ibs.getIbsClair();
 
		System.out.println("MESSAGE témoin");
		System.out.println(msg);
 
		System.out.println("bin MSG témoin");
		byte[] crypt0=ibs.getIbsCrypt(0);
		for(int i=0;i<crypt0.length;i++) System.out.print(crypt0[i]);
		System.out.println("");
		String msg2=new String(crypt0);
		System.out.println(msg2);
 
		System.out.println("bin MSG crypt[1]");
		byte[] crypt=ibs.getIbsCrypt(1);
		for(int i=0;i<crypt.length;i++) System.out.print(crypt[i]);
		System.out.println("");
		String msg3=new String(crypt);
		System.out.println(msg3);
 
		System.out.println("bin MSG decrypt[1]");
		byte[] decrypt=ibs.decryptIbs(crypt,1);
		for(int i=0;i<decrypt.length;i++) System.out.print(decrypt[i]);
		System.out.println("");
		String msg4=new String(decrypt);
		System.out.println(msg4);
	}
}
Par la même occasion quelqu'un pourrait-il m'éclairer sur le paramètre padding envoyé lors de l'init du Cipher. Je ne sais pas trop ce que je dois y mettre.

Merci