· 7 years ago · Sep 01, 2018, 03:10 AM
1Application still blocks even when using non-blocking cipher stream with socket
2CipherInputStream cis;
3 String salt = "1234567890123456";
4 String password = "abcdEFGH";
5
6 password = password.concat(salt);
7 String validpassword = password.substring(0, 16);
8 SecretKeySpec secretKey = new SecretKeySpec(validpassword.getBytes(),"AES");
9 AlgorithmParameterSpec paramSpec = new IvParameterSpec(salt.getBytes());
10
11 try {
12 // Creation of Cipher objects
13 Cipher encrypt =
14 Cipher.getInstance("AES/CFB8/NoPadding");
15 encrypt.init(Cipher.ENCRYPT_MODE, secretKey,paramSpec);
16
17 // Open the file
18 try {
19 fis = new FileInputStream(file);
20 } catch(IOException err) {
21 System.out.println("Cannot open file!");
22 return null;
23 }
24 cis = new CipherInputStream(fis, encrypt);
25
26 // Write to the Encrypted file
27 fos = new FileOutputStream(desFile);
28 byte[] b = new byte[256];
29 int i = cis.read(b);
30 while (i != -1) {
31 fos.write(b, 0, i);
32 i = cis.read(b);
33 }
34
35CipherInputStream cis;
36 String salt = "1234567890123456";
37 String password = "abcdEFGH";
38
39 password = password.concat(salt);
40 String validpassword = password.substring(0, 16);
41 SecretKeySpec secretKey =new SecretKeySpec(validpassword.getBytes(),"AES");
42 AlgorithmParameterSpec paramSpec = new IvParameterSpec(salt.getBytes());
43
44 try {
45 // Creation of Cipher objects
46 Cipher decrypt =
47 Cipher.getInstance("AES/CFB8/NoPadding");
48 decrypt.init(Cipher.DECRYPT_MODE, secretKey,paramSpec);
49
50 // Open the Encrypted file
51 cis = new CipherInputStream(is, decrypt);
52
53 int bytesRead;
54 int current = 0;
55 byte[] b = new byte[256];
56 bytesRead = cis.read(b,0,256);