0

我只需要通过响应是png图片来解密来自httpresponse的响应,所以我这样做了:

HttpPost httppost = new HttpPost(tileURLString);
nameValuePairs.add(new BasicNameValuePair("x", String.valueOf(ValueX)));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

如果我得到回应

HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
if (entity == null) {
    Log.i("Error","No content download");
}

InputStream in = entity.getContent();

这是工作。但我需要将此输出作为字符串使用 xor 解密,所以我所做的只是:

String responseText = EntityUtils.toString(response.getEntity());
InputStream in = new ByteArrayInputStream(responseText.getBytes());

PS。这仍然不能解密正常的输入流,但没有奏效。我google了一天。请帮帮我。如果这项工作我将进入下一步(解密)。提前致谢。

编辑:或者我使用这个方法将 InputStream 转换为字符串

private String convertStreamToString(InputStream is) {

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(is));
        StringBuilder sb = new StringBuilder();

        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                sb.append((line + "\n"));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return sb.toString();
    }

然后我用它来转换回输入流,但它也没有用。

    public InputStream convertStringToStream(String text)
            throws UnsupportedEncodingException {
        return new ByteArrayInputStream(text.getBytes("UTF-8"));
    }
4

2 回答 2

0
String responseText = EntityUtils.toString(response.getEntity());
InputStream in = new ByteArrayInputStream(responseText.getBytes());

变成

InputStream is = response.getEntity().getContent();
于 2012-05-08T03:37:05.137 回答
0

已解决的答案在此页面中

Android字节数组到字符串到字节数组

谢谢你的帮助。

于 2012-05-09T02:39:54.333 回答