小弟想做个基于udp协议的局域网传输软件  对文件和对话进行加密 可是文件加密老出问题。能调试运行通过 但传个图片什么的 图片发过去解密之后都会显示 串色 什么的不知道怎么回事  求指点 下边附上代码
public class SendFileThread extends Thread { //这是发送文件的关键代码  
byte b[] = new byte[4096]; public void run() { while (sendFileFlag) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
while (!sendFileFlag) {
try {
Thread.sleep(100);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
int rowNum = table.getSelectedRow();
int columnNum = table.getSelectedColumn();
if ((rowNum != -1) && (columnNum != -1)) {
hostName = (String) table.getValueAt(rowNum, columnNum);
} else {
flag2 = !flag2;
list.append("请指定文件的接收对象!!!!!\n");
sendFileFlag = !sendFileFlag;
}
if (flag1) {
new TimerThread().start();
list.append("开始发送\n");
long start = System.currentTimeMillis();
try {
int n = 0;
String host = hostName;
b = ThreeDES.getEncCode(b);  //  加密
while ((n = bis.read(b, 0, b.length)) != -1) {
bytes = bytes + n;
sendFile = new DatagramPacket(b, 0, n, InetAddress
.getByName(host), 8000);

fileSocket.send(sendFile);
Thread.sleep(0, 10); }
} catch (IOException e) { e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
long end = System.currentTimeMillis();
try {
bis.close();
} catch (IOException e1) {
e1.printStackTrace();
}
list.append("发送完毕,耗时:" + (end - start) + "毫秒\n");
try {
fileSocket.send(new DatagramPacket("%%%%%%".getBytes(),
0, "%%%%%%".getBytes().length, InetAddress
.getByName(hostName), 8000));
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
flag1 = !flag1;
sendFileFlag = !sendFileFlag;
}
if (flag2) {
try {      //ThreeDES.getEncString(fName + "@@******")
String fmsg =ThreeDES.getEncString(fName + "@@******");  //fName + "@@******"; sendFile = new DatagramPacket(fmsg.getBytes(), 0, fmsg
.getBytes().length, InetAddress
.getByName(hostName), 8001);

//sendFile = ThreeDES.getEncCode(sendFile);
fileSocket.send(sendFile); flag2 = !flag2;
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
while (sendFileFlag) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}  private class RecFileThread extends Thread {   //接收文件部分
public void run() {
while (recFileFlag) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
while (!recFileFlag) {
new Timer2Thread().start();
list.append("开始接收\n");
byte b[] = new byte[4096];
recFile = new DatagramPacket(b, 0, b.length);
while (true) {
try {
fileSocket.receive(recFile);
String temp = new String(recFile.getData(), 0, recFile
.getLength());

 if (temp.endsWith("%%%%%%")) {
bos.close();
list.append("接收完毕\n");
recFileFlag = !recFileFlag;
break;
}
b = ThreeDES.getDesCode(b);  //  解密
//recFile = new DatagramPacket(b,0,b.length);
bytes = bytes + recFile.getData().length;
bos.write(recFile.getData(), 0, recFile.getLength());
bos.flush();

} catch (IOException e) {
e.printStackTrace();
} } }
while (recFileFlag) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
这是加密算法。
public static byte[] getEncCode(byte[] byteS) {   
byte[] byteFina = null;
Cipher cipher;
try {
cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, key);
byteFina = cipher.doFinal(byteS);
} catch (Exception e) {
e.printStackTrace();
} finally {
cipher = null;
}
return byteFina;
}
public static byte[] getDesCode(byte[] byteD){
Cipher cipher;
byte[] byteFina=null;
try{
cipher =Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE,key);
byteFina = cipher.doFinal(byteD);
}catch(Exception e){
e.printStackTrace();
}finally{
cipher =null;
}
return byteFina;
}
求求各路大神帮帮小弟。要看着就要交毕业设计了唉