我正在尝试在 Netbeans Java 中加密我捕获的 IP 地址,但是当我运行我的表单时,我收到了消息addr is of illegal length
。为什么我会收到这个错误?
这是代码:
if (packet instanceof IPPacket) {
IPPacket ipp = (IPPacket) packet;
InetAddress dest = ipp.dst_ip;
KeyGenerator keygenerator;
try {
keygenerator = KeyGenerator.getInstance("DES");
SecretKey myDesKey = keygenerator.generateKey();
Cipher desCipher;
// Create the cipher
desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
desCipher.init(Cipher.ENCRYPT_MODE, myDesKey);
byte[] ipEncrypted = desCipher.doFinal(ipp.dst_ip.getAddress());
InetAddress src = ipp.src_ip;
// System.out.println(dest);
try {
ipp.dst_ip = InetAddress.getByAddress(ipEncrypted);
} catch(Exception e) {
System.out.println(e.getMessage());
}
ipp.src_ip = src;
} catch(Exception ex ) {
System.out.println(ex.getMessage());
}