0  down vote  favorite

I am trying to to download and decrypt an encrypted XML file.

I have implemented the download part and have tested with an
unencrypted file and it works fine.

However I now need to be able to download an XML file that has been
encrypted using AES and the key "XXXX"

So I am only concerned with decryption as the encryption on the XML
file is already done.

Here is my code so far:

 public NodeList getXMLDoc(){
        URL url;
        NodeList nl = null;

        try{
            String xmlFeed = context.getString(R.string.xml_feed);
            try {
                url = new URL(xmlFeed);
                URLConnection urlConnection;
                urlConnection = url.openConnection();
                HttpURLConnection httpConnection = (HttpURLConnection)
urlConnection;
                int responseCode = httpConnection.getResponseCode();

                if(responseCode == HttpURLConnection.HTTP_OK){

                    String bytes = toHex("XXXX");
                    SecretKeySpec skeySpec = new
SecretKeySpec(toByte(bytes), "AES");
                    try {
                        c.init(Cipher.DECRYPT_MODE, skeySpec);
                        //c.doFinal();
                    } catch (InvalidKeyException e) {
                        e.printStackTrace();
                    }
                    InputStream in = httpConnection.getInputStream();
                    CipherInputStream cis = new CipherInputStream(in,
c);
                    DocumentBuilderFactory dbf;
                    dbf = DocumentBuilderFactory.newInstance();
                    DocumentBuilder db = dbf.newDocumentBuilder();

                    Document dom = db.parse(cis);

                    Element docEle = dom.getDocumentElement();

                    nl = docEle.getElementsByTagName(TAG_CHAR);

                    }
            }
            catch (MalformedURLException e) {

                e.printStackTrace();
            }
            catch (IOException e) {

                e.printStackTrace();
            } catch (ParserConfigurationException e) {

                e.printStackTrace();
            } catch (SAXException e) {

                e.printStackTrace();
            }
            }
            finally{

            }
        return nl;
    }

At the minute I am trying to decrypt the whole file using
CipherInputStream is this the correct approach?

My code above gives me the following exception:

WARN/System.err(5274): java.io.IOException: last block incomplete in
decryption

Is this a setup error or what might be causing this error?

Are there any tutorials on how to decrypt an XML file in Android/Java?

Am I going in the right direction as to how to decrypt the file or is
my code completely wrong?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to