我正在尝试连接到 Tor 网络以发送匿名 HTTP 请求。但它抛出IllegalBlockSizeException
。我用过silvertunnel.org_netlib.jar
public static void main(String[] args) {
try {
// TODO code application logic here
NetLayer lowerNetLayer = NetFactory.getInstance().getNetLayerById(NetLayerIDs.TOR);
lowerNetLayer.waitUntilReady();
NetlibURLStreamHandlerFactory factory = new NetlibURLStreamHandlerFactory(false);
factory.setNetLayerForHttpHttpsFtp(lowerNetLayer);
String urlStr = "http://www.whatismyip.com/";
URLStreamHandler handler = factory.createURLStreamHandler("http");
URL context = null;
URL url = new URL(context, urlStr, handler);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("GET");
//connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
//connection.setRequestProperty("Content-Length", String.valueOf(postData.length()));
// Write data
OutputStream os = connection.getOutputStream();
// Read response
StringBuilder responseSB = new StringBuilder();
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ( (line = br.readLine()) != null)
responseSB.append(line);
// Close streams
br.close();
os.close();
Document doc=Jsoup.parse(responseSB.toString());
} catch (IOException ex) {
System.out.println(ex);
}
}
我收到了这个错误:
`WARNING: Directory.updateNetworkStatusNew Exception
java.lang.RuntimeException: javax.crypto.IllegalBlockSizeException: Data must not be longer than 256 bytes
at org.silvertunnel.netlib.layer.tor.util.Encryption.verifySignature(Encryption.java:272)
at org.silvertunnel.netlib.layer.tor.directory.DirectoryConsensus.<init>(DirectoryConsensus.java:117)
at org.silvertunnel.netlib.layer.tor.directory.Directory.updateNetworkStatusNew(Directory.java:377)
at org.silvertunnel.netlib.layer.tor.directory.Directory.refreshListOfServers(Directory.java:287)
at org.silvertunnel.netlib.layer.tor.directory.DirectoryManagerThread.updateDirectory(DirectoryManagerThread.java:60)
at org.silvertunnel.netlib.layer.tor.directory.DirectoryManagerThread.run(DirectoryManagerThread.java:76)
Caused by: javax.crypto.IllegalBlockSizeException: Data must not be longer than 256 bytes
at com.sun.crypto.provider.RSACipher.doFinal(RSACipher.java:337)
at com.sun.crypto.provider.RSACipher.engineDoFinal(RSACipher.java:382)
at javax.crypto.Cipher.doFinal(Cipher.java:2087)
at org.silvertunnel.netlib.layer.tor.util.Encryption.verifySignature(Encryption.java:251)
... 5 more
`