내 암호화 된 파일을 읽고 해독 된 내용을 목록에 넣으려는 중, 끝에있는 일부 줄이 임의로 또는 새 줄의 중간에 나뉘어 있습니다. 왜 이런 짓을 한거야? (해독 방법에서). Btw 버퍼가 1024이면 도움이된다.파일을 목록으로 해독 할 때 줄을 분할하는 중
public Crypto() {
try {
PBEKeySpec keySpec = new PBEKeySpec(password.toCharArray());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey key = keyFactory.generateSecret(keySpec);
ecipher = Cipher.getInstance("PBEWithMD5AndDES");
dcipher = Cipher.getInstance("PBEWithMD5AndDES");
byte[] salt = new byte[8];
PBEParameterSpec paramSpec = new PBEParameterSpec(salt, 100);
ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
} catch (Exception e) {
}
}
@SuppressWarnings("resource")
public static List<String> decrypt(String file) {
List<String> list = new LinkedList<String>();
try {
InputStream in = new CipherInputStream(new FileInputStream(file), dcipher);
int numRead = 0;
while ((numRead = in.read(buffer)) >= 0) {
list.add(new String(buffer, 0, numRead);
}
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
의 새로운
try-with-resources
구조를 사용 할 수 있습니다, 필요 이것은 실제 코드가 될 수 없습니다. –문자열을 1024 바이트 길이의'List' 문자열로 읽는 중입니다. - 한 줄씩 읽으려는 경우,'list.add (new String (buffer, 0, numRead); 새로운 BufferedReader (새로운 InputStreamReader (새로운 CipherInputStream (새로운 FileInputStream (file), dcipher)))'가이 트릭을 수행해야합니다. –
정말 고마워요. !!! 그것은 xD를 작동합니다. – CBennett