【问题标题】:Unable to connect to tor network using silvertunnel netlib in java无法在java中使用silvertunnel netlib连接到tor网络
【发布时间】:2014-06-20 11:12:47
【问题描述】:

我正在尝试连接到 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
`

【问题讨论】:

    标签: java tor silvertunnel


    【解决方案1】:

    System.setProperty('socksProxyHost','127.0.0.1');

    System.setProperty('socksProxyPort','9051');

    在 main 方法中添加这两行并使用 vidalia for tor

    【讨论】:

    • 使用也可以使用Autoidetityswitcher进行身份切换。
    • 这个答案没有回答这个问题,而是建议了一个不同的工具和一个死网站的链接。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-08
    • 2021-09-15
    相关资源
    最近更新 更多