4362:65c8342f726a | 4363:2c7f594145dc |
---|---|
52 Cipher cipher; | 52 Cipher cipher; |
53 Cipher dCipher; | 53 Cipher dCipher; |
54 String paddingStr = "PKCS5Padding"; | 54 String paddingStr = "PKCS5Padding"; |
55 AlgorithmParameters algParams; | 55 AlgorithmParameters algParams; |
56 SecretKey key; | 56 SecretKey key; |
57 int ivLen; | |
58 | 57 |
59 static int numThreads = 0; | 58 static int numThreads = 0; |
60 int threadId; | 59 int threadId; |
61 static synchronized int getThreadId() { | 60 static synchronized int getThreadId() { |
62 int id = numThreads; | 61 int id = numThreads; |
66 | 65 |
67 abstract public void run(); | 66 abstract public void run(); |
68 | 67 |
69 public void prepare() { | 68 public void prepare() { |
70 try { | 69 try { |
71 System.out.println("\nmsgSize=" + msgSize + ", key size=" + keySize + ", reInit=" + !noReinit + ", checkOutput=" + checkOutput); | 70 System.out.println("\nalgorithm=" + algorithm + ", mode=" + mode + ", msgSize=" + msgSize + ", keySize=" + keySize + ", noReinit=" + noReinit + ", checkOutput=" + checkOutput); |
72 | 71 |
73 int keyLenBytes = (keySize == 0 ? 16 : keySize/8); | 72 int keyLenBytes = (keySize == 0 ? 16 : keySize/8); |
74 byte keyBytes[] = new byte[keyLenBytes]; | 73 byte keyBytes[] = new byte[keyLenBytes]; |
75 if (keySize == 128) | 74 if (keySize == 128) |
76 keyBytes = new byte[] {-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7}; | 75 keyBytes = new byte[] {-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7}; |
88 } | 87 } |
89 | 88 |
90 cipher = Cipher.getInstance(algorithm + "/" + mode + "/" + paddingStr, "SunJCE"); | 89 cipher = Cipher.getInstance(algorithm + "/" + mode + "/" + paddingStr, "SunJCE"); |
91 dCipher = Cipher.getInstance(algorithm + "/" + mode + "/" + paddingStr, "SunJCE"); | 90 dCipher = Cipher.getInstance(algorithm + "/" + mode + "/" + paddingStr, "SunJCE"); |
92 | 91 |
93 ivLen = (algorithm.equals("AES") ? 16 : algorithm.equals("DES") ? 8 : 0); | 92 if (mode.equals("CBC")) { |
94 IvParameterSpec initVector = new IvParameterSpec(new byte[ivLen]); | 93 int ivLen = (algorithm.equals("AES") ? 16 : algorithm.equals("DES") ? 8 : 0); |
95 | 94 IvParameterSpec initVector = new IvParameterSpec(new byte[ivLen]); |
96 cipher.init(Cipher.ENCRYPT_MODE, key, initVector); | 95 cipher.init(Cipher.ENCRYPT_MODE, key, initVector); |
96 } else { | |
97 algParams = cipher.getParameters(); | |
98 cipher.init(Cipher.ENCRYPT_MODE, key, algParams); | |
99 } | |
97 algParams = cipher.getParameters(); | 100 algParams = cipher.getParameters(); |
98 dCipher.init(Cipher.DECRYPT_MODE, key, algParams); | 101 dCipher.init(Cipher.DECRYPT_MODE, key, algParams); |
99 if (threadId == 0) { | 102 if (threadId == 0) { |
100 childShowCipher(); | 103 childShowCipher(); |
101 } | 104 } |