I am working on a school project and am having a bit of a problem with the two following functions. If I use the ImportArray function it will throw an IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher. As far as I could tell that was because the byte arrays I was creating on the import from the input strings after they were split up were not the same as before. Perhaps I am viewing this all wrong. Any chance you could tell me where I have made a mistake here?
public void ImportArray() throws Exception { FileReader inputFile = new FileReader("students.txt"); Scanner scannedFile = new Scanner(inputFile); String buffer = null; String[] splitter; while (scannedFile.hasNext()) { if(buffer == null) { buffer = scannedFile.next(); } else { buffer = buffer + scannedFile.next(); } } scannedFile.close(); splitter = buffer.split(delimiter); for (int i = 0; i < splitter.length; i++) { Student ImportedStudent = new Student(); String stemp1 = splitter[i]; byte[] temp1 = stemp1.getBytes(); byte[] temp2 = splitter[i+1].getBytes(); byte[] temp3 = splitter[i+2].getBytes(); byte[] temp4 = splitter[i+3].getBytes(); byte[] temp5 = splitter[i+4].getBytes(); String STemp1 = EMan.DecodeDataString(temp1); String STemp2 = EMan.DecodeDataString(temp2); String STemp3 = EMan.DecodeDataString(temp3); String STemp4 = EMan.DecodeDataString(temp4); String STemp5 = EMan.DecodeDataString(temp5); ImportedStudent.FirstName = STemp1; ImportedStudent.LastName = STemp2; ImportedStudent.CurrentTest = STemp3; ImportedStudent.CurrentGrade = Double.valueOf(STemp4); ImportedStudent.TestCompleted = Boolean.valueOf(STemp5); push(ImportedStudent); i = i + 4; } } public void ExportArray() throws InvalidKeyException, BadPaddingException, IllegalBlockSizeException, IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException { FileWriter outputFile = new FileWriter ("students.txt", false); String encryptedStudent = ""; for (int i = 0; i < StudentArray.length; i++) { Student ExportStudent = StudentArray[i]; if(ExportStudent != null) { byte[] temp1 = EMan.EncodeDataString(ExportStudent.FirstName); byte[] temp2 = EMan.EncodeDataString(ExportStudent.LastName); byte[] temp3 = EMan.EncodeDataString(ExportStudent.CurrentTest); String STemp1 = String.valueOf(ExportStudent.CurrentGrade); byte[] temp4 = EMan.EncodeDataString(STemp1); String STemp2 = String.valueOf(ExportStudent.TestCompleted); byte[] temp5 = EMan.EncodeDataString(STemp2); if(i > 0) { encryptedStudent = delimiter + temp1 + delimiter + temp2 + delimiter + temp3 + delimiter + temp4 + delimiter + temp5; } else { encryptedStudent = temp1 + delimiter + temp2 + delimiter + temp3 + delimiter + temp4 + delimiter + temp5; } outputFile.write(encryptedStudent); } } outputFile.close(); }