|
10 | 10 | import java.io.ObjectOutputStream; |
11 | 11 | import java.io.OutputStream; |
12 | 12 | import java.net.URL; |
| 13 | +import java.security.InvalidKeyException; |
13 | 14 | import java.security.MessageDigest; |
14 | 15 | import java.security.NoSuchAlgorithmException; |
15 | 16 | import java.security.Principal; |
| 17 | +import java.security.spec.InvalidKeySpecException; |
| 18 | +import java.security.spec.KeySpec; |
16 | 19 | import java.util.List; |
17 | 20 |
|
18 | 21 | import javax.crypto.BadPaddingException; |
19 | 22 | import javax.crypto.Cipher; |
20 | 23 | import javax.crypto.IllegalBlockSizeException; |
21 | 24 | import javax.crypto.NoSuchPaddingException; |
| 25 | +import javax.crypto.SecretKey; |
| 26 | +import javax.crypto.SecretKeyFactory; |
| 27 | +import javax.crypto.spec.DESKeySpec; |
| 28 | +import javax.crypto.spec.SecretKeySpec; |
22 | 29 | import javax.servlet.http.HttpServletResponse; |
23 | 30 |
|
24 | 31 | import org.apache.commons.io.IOUtils; |
@@ -219,8 +226,28 @@ public void getMaliciousCertificate(final HttpServletResponse response, final Ac |
219 | 226 |
|
220 | 227 | } |
221 | 228 |
|
222 | | - private static byte [] getCipher(byte [] data) throws IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException { |
| 229 | + private static byte [] getCipher(byte [] data) throws IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidKeySpecException { |
223 | 230 | Cipher cipher = Cipher.getInstance("DES"); |
| 231 | + |
| 232 | + byte[] keyBytes = { |
| 233 | + 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) (Math.random()*0xCD), (byte) 0xEF |
| 234 | + }; |
| 235 | + |
| 236 | + // Create a DES key specification |
| 237 | + KeySpec keySpec = new DESKeySpec(keyBytes); |
| 238 | + |
| 239 | + // Create a SecretKeyFactory for DES |
| 240 | + SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); |
| 241 | + |
| 242 | + // Generate a SecretKey object |
| 243 | + SecretKey secretKey = keyFactory.generateSecret(keySpec); |
| 244 | + |
| 245 | + // Create a SecretKeySpec object from the SecretKey |
| 246 | + SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getEncoded(), "DES"); |
| 247 | + |
| 248 | + |
| 249 | + |
| 250 | + cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); |
224 | 251 | return cipher.doFinal(data); |
225 | 252 | } |
226 | 253 |
|
|
0 commit comments