使用Java的基本授权(1.5)

时间:2015-11-04 10:10:02

标签: java twilio

  

注意:我们的Host应用程序调用此JAR文件(实际上是   class)仅支持JVM 1.5。由于代码的触发器来自   应用程序,我们没有任何其他去限制我们的Java   代码与JDK 1.5的兼容性。

以下是我尝试过的代码:

        String webPage = "https://api.twilio.com/2010-04-01/Accounts";
        URL url = new URL(webPage);
        URLConnection urlConnection = url.openConnection();
        urlConnection.setRequestProperty("Authorization", "Basic BASE64ECONDED_STRING_OF_LENGTH_93_CHARACTERS_WITHOUT_ANY_WHITESPACE");
        //((HttpURLConnection) urlConnection).setRequestMethod("GET");//I get same error with or without this
        InputStream is = urlConnection.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);

        int numCharsRead;
        char[] charArray = new char[1024];
        StringBuffer sb = new StringBuffer();
        while ((numCharsRead = isr.read(charArray)) > 0) {
            sb.append(charArray, 0, numCharsRead);
        }
        String result = sb.toString();

        System.out.println("*** BEGIN ***");
        System.out.println(result);
        System.out.println("*** END ***");

我一直收到的错误是:

javax.net.ssl.SSLKeyException: RSA premaster secret error
    at com.sun.net.ssl.internal.ssl.PreMasterSecret.<init>(PreMasterSecret.java:86)
    at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverHelloDone(ClientHandshaker.java:514)
    at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:160)
    at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:495)
    at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:433)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:815)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1025)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1038)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:405)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:170)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:913)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
    at test.SmsSender.TwilSend(SmsSender.java:117)
    at test.SmsSender.main(SmsSender.java:26)
Caused by: java.security.InvalidKeyException: Illegal key size or default parameters
    at javax.crypto.Cipher.a(DashoA12275)
    at javax.crypto.Cipher.a(DashoA12275)
    at javax.crypto.Cipher.a(DashoA12275)
    at javax.crypto.Cipher.init(DashoA12275)
    at com.sun.net.ssl.internal.ssl.RSACipher.encryptInit(RSACipher.java:40)
    at com.sun.net.ssl.internal.ssl.PreMasterSecret.<init>(PreMasterSecret.java:83)
    ... 13 more

看起来Java 1.5中不支持基本授权。完全相同的代码适用于Java 1.7。我也得到了成功的回应。 有没有办法让它在Java 1.5中运行?

0 个答案:

没有答案