XML deserialize and decrypting encoding problem. Please help me

This is my first topic here, so at first I'd like to say "Hi" everyone and apologise for my bad english ;)
I have just finished my new application about signing/checking and encrypting/decrypting XML files. I use Apache XML Security packages to do this.
Everything works fine, instead of one...
I'm Polish and sometimes I have to encrypt or decrypt XML which includes polish letters like: 'ą' , 'ę', 'ł' and some others... If I encrypt such file, it succeeds. The problem is when I try to decrypt such an encrypted file. I recieve an error like :
"[Fatal Error] :2:7: An invalid XML character (Unicode: 0x19) was found in the element content o
f the document.
gov.mf.common.exceptions.SenderException: E_SENDER_DECRYPTION
at gov.mf.common.xml.encryption.EncryptTool.decrypt(Unknown Source)
at gov.mf.CERBER.TestCBR.main(Unknown Source)
Caused by: org.apache.xml.security.encryption.XMLEncryptionException: An invalid XML character
(Unicode: 0x19) was found in the element content of the document.
Original Exception was org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x19)
was found in the element content of the document.
at org.apache.xml.security.encryption.XMLCipher$Serializer.deserialize(Unknown Source)
at org.apache.xml.security.encryption.XMLCipher.decryptElement(Unknown Source)
at org.apache.xml.security.encryption.XMLCipher.doFinal(Unknown Source)
... 2 more
What's wrong? My XML document is UTF-8 encoded, with or without BOM. I wrote in in Notepad++ or any other editior which has UTF-8 encoding.
I'm parsing my XML with DOM. There is an interesting line in an error above like: " at org.apache.xml.security.encryption.XMLCipher$Serializer.deserialize(Unknown Source)" , do you know that?
Everything is fine when I try to encrypt/decrypt '�' or 'ń', but things go wrong with 'ą', 'ę', 'ł' and others... I also managed to encrypt and decrypt 'ł' but unfortunately, after decryption 'ł' turns into 'B'. It obviously an encoding problem, but how to fix it?
I would be really thankfull if some of You guys would help me.
Looking forward fo any answers.
Matthew
Message was edited by:
matthew_pl

Hi once again.
I still don't havy any solution to my problem. I used Apache XML Security examples to encrypt/decrypt my XML document with Polish charaters but I also recieve the same error. What's wrong?
Here is some code:
----- Parsing XML do Document ------
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     //Bardzo wazna linijka - bless TEK ;)
     factory.setNamespaceAware(true);
     DocumentBuilder builder;
     builder = factory.newDocumentBuilder();
     File f = new File(Const.FILE_IN_PATH + File.separator + Const.FILE_IN);     
     org.w3c.dom.Document doc = builder.parse(f);
---------- Encrypting & Decrypting XML document (whole class) -------------
import java.io.*;
import java.security.*;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.apache.xml.security.keys.KeyInfo;
import org.apache.xml.security.utils.EncryptionConstants;
import org.apache.xml.security.encryption.XMLCipher;
import org.apache.xml.security.encryption.EncryptedData;
import org.apache.xml.security.encryption.EncryptedKey;
public class EncryptTool
private PublicKey publicKey;     
private PrivateKey privateKey;
static
org.apache.xml.security.Init.init();
public EncryptTool()
     publicKey = KeyStores.getCerberPublicKey();
     privateKey = KeyStores.getCerberPrivateKey();
public Document encrypt(Document doc, String sufix)
try
     byte[] passPhrase = "24 Bytes per DESede key!".getBytes("UTF-8");
     DESedeKeySpec keySpec = new DESedeKeySpec(passPhrase);
     SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
     SecretKey secretKey = keyFactory.generateSecret(keySpec);
     XMLCipher keyCipher = XMLCipher.getInstance(XMLCipher.RSA_v1dot5);
     keyCipher.init(XMLCipher.WRAP_MODE, publicKey);
     EncryptedKey encryptedKey = keyCipher.encryptKey(doc, secretKey);
          Element elementToEncrypt = (Element) doc.getDocumentElement();
          System.out.println("Szyrfuję: " + elementToEncrypt.getTextContent());
          XMLCipher xmlCipher = XMLCipher.getInstance(XMLCipher.TRIPLEDES);
          xmlCipher.init(XMLCipher.ENCRYPT_MODE, secretKey);
          EncryptedData encryptedDataElement = xmlCipher.getEncryptedData();
          KeyInfo keyInfo = new KeyInfo(doc);
          keyInfo.add(encryptedKey);
          encryptedDataElement.setKeyInfo(keyInfo);
          boolean encryptContentsOnly = true;
          xmlCipher.doFinal(doc, elementToEncrypt, encryptContentsOnly);
          // output the resulting document
          String [] parts = Const.FILE_IN.split("\\.");
          String saveAs = Const.FILE_OUT_PATH + File.separator + parts[0] + sufix + "." + parts[1];
          OutputStream os = new FileOutputStream(saveAs);
          XMLUtil.sameXMLtoFile(doc, os);
} catch (Exception ex)
     throw new TestCBRException("E_CERBER_ENCRYPTION", ex);
return doc;
public void decrypt(Document doc, String sufix) throws SenderException
try
          String namespaceURI = EncryptionConstants.EncryptionSpecNS;
     String localName = EncryptionConstants._TAG_ENCRYPTEDDATA;
     int ile = doc.getElementsByTagNameNS(namespaceURI, localName).getLength();
     if (ile == 0) throw new SenderException("E_SENDER_DECRYPTION_NEEDED");
     for(int i=0; i < ile; i++)
     Element encryptedDataElement = (Element) doc.getElementsByTagNameNS(namespaceURI, localName).item(0);
     XMLCipher xmlCipher = XMLCipher.getInstance();
     xmlCipher.init(XMLCipher.DECRYPT_MODE, null);
     xmlCipher.setKEK(privateKey);
     xmlCipher.doFinal(doc, encryptedDataElement);
               String [] parts = Const.FILE_IN.split("\\.");
               String saveAs = Const.FILE_OUT_PATH + parts[0] + sufix + "." + parts[1];
               OutputStream os = new FileOutputStream(saveAs);
                    XMLUtil.saveXMLtoFile(doc, os);
} catch (SenderException ex) {
     throw ex;
} catch (Exception ex) {
     throw new SenderException("E_SENDER_DECRYPTION", ex);
Please help me. I'm going into madness what's wrong with it...

Similar Messages

  • Problem: codebase, jar and image reloading problem please help!

    Hi Java Gurus,
    I have written an applet that extends JApplet for viewing webcam. In order to reduce the download time I put my classes into a doorcam.jar file. The following is my <applet> tag in my html file.
    <applet code="CameraApplet.class"
    archive="doorcam.jar"
         codebase = "webcam/classes"
         width="375" height="475">
    <param name="imagePath" value="http://judge/webcam/images">
    <param name="webCamImage" value="door.jpg">
    <param name="COMPort" value="COM2">
    <param name="frameRate" value="10"> <!-- could not exceed more than 10-->
    <param name="host" value="judge">
    </applet>
    The fist problem is that my class file does not get loaded from the jar file if i provide the "codebase" attribute as above. Instead the browser load every single class file from the webserver. This has some problem too. Coz the browser sometimes just thorough NullPointerException or ClassNotFoundException. After much of debugging I found out that the problem is the IE browser which seldom fails to load classes or image file from the server. If i referesh the browser the applet and all its classes loaded successfully and runs smoothly. This behaviour never occurs when running with "appletviewer".
    I wanted all my classes to be loaded from my jar file. After much of trial and error I found out that if i remove "codebase" attribute the browser loads the classes from my jar file and applet loads very fast. This is where the second problem comes in. The browser does not reload my webcam image file so that the webcam become alive with live images, like before.
    If I run on "appletviewer" everything works fine my web cam is displayed properly. But in IE browser the image does not get reloaded when I refresh my image to give live to my webcam display. The refresh method is given below.
    private void refresh(final URL url) {
    Image webCamImage =getImage(url);
    webCamImage.flush(); // flush out the previous image
    webCamImage = getImage(url); // get a new image
    webCamImageIcon.setImage(webCamImage); webCamImageIcon.paintIcon(webCamLabel, webCamLabel.getGraphics(), 15, 15);
    When I add the "codebase" attribute back, the image gets reloaded for every refresh() and everything works fine. But the classes are also loaded from the server. And occasionally also suffers Class loading and image loading problem. As I presented earlier, when I do refreshing in the browser everything gets loaded and the applet function correctly with web cam displaying very well.
    The problem is so strange that I could not find any way to solve it.
    It would be a great help to me if somebody provide me some work around to the problem.
    I tested on Windows 2000, Windows XP, IE 5.5, IE 6 with J2SDK 1.4.0.
    Thank you all very much in advance.
    best regards,
    Judge

    Thank you so much for the suggestions. I did tried the way u suggested. The problem still the same.
    I think its the problem between IE browser and Java Plug-in.
    I which SUN would find these incompatibilities and solve these problems.
    I even tried using java SDK and plug-in 1.4.1 it even worst. It can't even load an applet. And it does not show any loading messages nor any error messages. It just show a cross sign on the upper left coner.
    I would be so glad, if Sun would try to eliminate the inconsistancies such as caching, loading, initializing etc between browser and its Java plug-In. For example, applets behave well in appletviewer and behave unpredictably in browser environment.
    I have seen so many people in the forums with all sorts of problems because of this.
    Right now I m desperately looking for work around to my problem.
    If somebody would provide me with the solution to my problem it would be a great help to me.
    thank you all so much.
    best regards,
    Judge

  • G585 wired and wifi networking problems - please help!!

    Just purchased a new G585 a couple weeks ago.  After trying Win 8, I realized what a complete POS of an OS it is and installed Win 7.
    2 Major problems:
    1.  Ethernet connection erratically disconnects - no rhyme or reason - sometimes works other times doesn't.  I've tested on two diff networks - the same behavior.
    2.  Cannot install wifi - tried the drivers from Lenovo site - no go - tried drivers someone had recommended (broadcom wifi5.100.196.18) these did not work either - device still unrecognized in device manager
    This is my 9th Lenovo laptop over the years.  The others were great.  This one seems to have serious issues.
    Can anyone assist please???

    I have had these same connectivity issue since I bought the laptop in March of 2013.  It is January 2014, and is will still drop connectivity for no apparent reason, be incredibly slow when it IS connected, and sometimes just sop seeing the network altogether (and this happens on every netwrok I have attempted to connect to).
    The most obnoxious thing is that after spending several hours over multiple days on the phone with tech supprt, they said I needed to send it in for repair.  So I did.  It was gone two weeks and when I got ti back, they claimed that had repaired it, but everything was exactly the same.
    Combine that with the lack of help for the company and the fact that this seems to be the only laptop where edge swipes on the touchpad cannot be disabled, this Lenovo laptop is the worst computer I have ever owned, period.  And I mean ever.
    If there ACTUALLY IS a way to fix this issue, I would love to hear it, bit nothing that anywone ever suggest actually works.  I thought maybe if I upgraded to Windows 8.1 it would help, but the Lenovo site lists the G585 as a model you shouldn't update because of monitor driver issues witht he upgrade.  It really looks to me like Lenovo has written this model off completely.
    I will never buy another Lenovo product and I will direct other people to other brands.  Words cannot describe my frustration and disappointment.

  • Ipod Nano 3G and Bose Sounddock Problems - Please help if you can?

    Hi all,
    Hope you can help me out, I have just purchased a Nano 3G and its all fine when working with head phones.
    Tried it in my Bose Sounddock and it has several issues:
    1) will not charge at all
    2) will not let me change songs when docked
    3) when removed it locks for up to 20 secs
    4) bose remote will only let me alter volume not songs or rewind
    5) if I press off on Bose remote it goes off for 5 secs then comes back on
    Please can anyone help explain or offer solutions to this please.
    many thanks
    Chris mills

    Hi megan,
    I am swapping my Ipod this weekend. it's a fault with them and I don't think anyone has the answer to solve it.
    hope you can do the same.
    cheers
    chris

  • Encoding problem please help..

    I am using XML parser V2.0.7 for C++.
    I have a stylesheet wherein
    <xsl:template match="some japanaese char">
    When I run XSLSample , the XSLT processor thorws an error complaining LPX-314. Please reply

    You have to do two things:
    1. set the stylesheet encoding to japanease/unicode
    2. Save the file with the same encoding using xml editor that support file saving with non-ascii charset. I think xmlspy support this.
    Hadar

  • Encoding problem please help ASAP!!!

    So i am doing a project for school (been working on it for weeks) and i finally finished it and when i try to export it, its all messed up. I dont get an error of any kind but i get a media offline screen everywhere there is supposed to be video (.mp4) im currently using CC 2014..... I also tried exporting to media encoder and still no luck.

    You have to do two things:
    1. set the stylesheet encoding to japanease/unicode
    2. Save the file with the same encoding using xml editor that support file saving with non-ascii charset. I think xmlspy support this.
    Hadar

  • Firewire and audio interface problem, please help

    Hi all
    I'm not being lazy, i've spent hours trawling through forums and google trying to find a fix but cant so hope someone here can help.
    Basically, I've been using my Macbook for Logic Studio with an audio interface (Motu 8pre). This was connected via firewire 400 to firewire 400 and worked absolutely fine no problems.
    I've recently got a Mac Pro. I've installed Logic onto it, my Motu 8pre driver etc etc and noticed that the firewire socket on the Mac Pro is different. I've been on the Motu website and quite clearly they say that a firewire 400 to firewire 800 cable will work fine with modern macs (this can be seen in more detail at bottom right of this web page http://www.motu.com/products/motuaudio/8pre
    I've bought one of these cables and plugged them into my interface and Mac Pro respectively, switched on the device as i have been doing for the past year with my Macbook, but the MacPro just wont seem to recognise it.
    How can I get this interface to work with my Mac Pro?
    I've tried connecting to different ports on back and front, restarting machine but it just wont work.
    Am I missing something simple here?
    Can anyone help?
    Thanks in advance
    Adam

    Ok its official I AM a muppet.
    Went onto motu site again and noticed they released an update driver for snow leopard. Downloaded it and it works fine.
    Fixed.
    Thanks

  • Clone Stamp and Healing brush problem, please help!

    Hi there, I'm new to the forum but I have been using Adobe creative suite for quite some time now.  As the thread title describes, I'm having an issue with my photoshop clone stamp and healing brush tool that I can't seem to fix on my own. I searched the internet all day, scrolling over many other posts but I can't seem to find anyone else who is having similar issues like I am having here.
    This is kinda hard to explain but the issue I am having, is that when I go to use either my clone stamp or healing brush tool, the layer I am working on whether it is a flattened background or normal editable layer, get shifted as soon as I press the option key to make a selection and then when I go to move to the area to use these tools it acts like I've duplicated the entire layer and drags it around the screen, even though no such copy and paste has been made.  All of my other tools are working normally and I wasn't having this issue last time I worked on anything in photoshop.
    I am running:
    a Mac OSX 10.5.8
    CS4 extended version 11.0.2
    Any and all help is greatly appreciated.

    Your probably seeing the clone source overlay.
    Go to Window>Clone Source and either uncheck:
    Show Overlay for no overlay or check clipped to show the overlay
    clipped to the size of the brush.
    There is also a photoshop  macintosh forum for future reference
    (you posted in the photoshop elements forum)
    http://forums.adobe.com/community/photoshop/photoshop_macintosh
    MTSTUNER

  • Problem with Spotlight and some system problem, Please HELP!

    I'm using iMac G5 with iSight (10.4.8)
    Recently, I've noticed that my spotlight didn't search anything, when I type something it just do nothing.
    I try to re indexing the spotlight by move the HD to the privacy zone in the spotlight preference but nothing appear on the list. I can't add anything to the privacy zone both by draging the folder or click + button.
    Then I search for the application that can clear the cache and re indexing the spotlight, I found Onyx and Maintenance.
    Both of them can't be open, it say that I have to use an admin account.
    Even I was logged in as a Admin, I have only one account in the system and set as an admin already.
    So, I search on the internet and someone suggest another way to re index in terminal by using this command: sudo mdutil -E /
    First I open the terminal and type the command, it said "-bash: sudo: command not found "
    So, I try to use terminal by boot on the DVD that bundle with iMac, and same result.
    I tried boot in single user by press command and S when boot and type sudo command, same reult.
    Another information, I noticed on my macbook when I open the terminal, it will show this info:
    Last login: show the time
    Welcom to Darwin!
    My computer name
    But on my iMac, it didn't show anything except only the computer name line.
    What should I do? Thanks

    Highly recommend that you read, reread and understand the consequences and then follow the directions as presented on X Lab
    http://www.thexlab.com/faqs/stopspotlightindex.html
    That is before you follow some of the directions you find on some of these discussions. Even mine.

  • My Itunes is no longer allowing me to manage my music on my phone i can no longer select on my iphone to make playlists and delete music. Please help fix my problem.

    My Itunes is no longer allowing me to manage my music on my phone i can no longer select on my iphone to make playlists and delete music. Please help fix my problem. Iphone4s, 32gigs, IOS 7.1.2
    I don't know why it stopped working but it happened a month or two ago but the option on this phone that's usually all the way to the left when you select your device but now its not and I don't know what caused it. ive already tried troubleshooting my problem but have found no help.

    Hello Salmomma,
    Thank you for the details of the issue you are experiencing when trying to connect your iPhone to your Mac.  I recommend following the steps in the tutorial below for an issue like this:
    iPhone not appearing in iTunes
    http://www.apple.com/support/iphone/assistant/itunes/
    Additionally, you can delete music directly from the iPhone by swiping the song:
    Delete a song from iPhone: In Songs, swipe the song, then tap Delete.
    iPhone User Guide
    http://manuals.info.apple.com/MANUALS/1000/MA1658/en_US/iphone_ios6_user_guide.p df
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • My iphone is on recovery mode and i can´t turn on it, when i try to recover it from itunes i get: "unknown error (36), i´ve tried to do lot of things but i can´t  solve my problem. please help!!

    my iphone is on recovery mode and i can´t turn on it, when i try to recover it from itunes i get: unknown error (36), i´ve tried to do lot of things but i can´t solve my problem. please help!!

    Hi, i had the same problem. Try to find the file "apple" or "itunes" don't know it anymore exactly. Ahm well you need to delet any information or just plug in your iphone into an other computer. important is that your iphone never has been pluged in this computer before. This was what i did, and it worked!

  • I want to buy an in-app purchase but i don`t remember my security questions and i cant access my recovery email either, what can i do? i have 100$ on my account and cant use it because of that problem, please help URGENT

    I want to buy an in-app purchase but i don`t remember my security questions and i cant access my recovery email either, what can i do? i have 100$ on my account and cant use it because of that problem, please help URGENT

    If you have a rescue email address on your account then you can use that - follow steps 1 to 5 half-way down this page will give you a reset link on your account : http://support.apple.com/kb/HT5312
    If you don't have a rescue email address (you won't be able to add one until you can answer your questions) then you will need to contact Support in your country to get the questions reset : http://support.apple.com/kb/HT5699

  • I'm in trouble, my iPod Touch is giving 4th shock when recharge and the battery does not last any more. who knows or has a similar problem, please help me. Note: all this after I downloaded the new version OS5.

    I'm in trouble, my iPod Touch is giving 4th shock when recharge and the battery does not last any more. who knows or has a similar problem, please help me. Note: all this after I downloaded the new version OS5.

    I would make an appointment at the Genius Bar of an Apple store because of the shock issue. I doubt it was caused by the update.

  • Hi, After I installed Mac Lion, I have problem with the tamil font while typing in Neo Office. Especially with the letters "e-Ex: தெ" and "ai-Ex:தை". Please help me I know its not bug from Apple It shd be some problem in neo.

    Hi, After I installed Mac Lion, I have problem with the tamil font while typing in Neo Office. Especially with the letters "e-Ex: தெ" and "ai-Ex:தை". Please help me I know its not bug from Apple It shd be some problem in neo.

    Is your problem due to the keyboard or to NeoOffice Characters? You have to change probably the font. Not all fonts are supporting all Unicode sets. Which font you have in your NeoOffice set to write Tamil? Try with Arial Unicode MS for example.
    Are the letter e-Ex and ai-Ex right in your posting? If they are right, how you inserted these letters in your posting? By copy and paste or by typing? If by typing, your question is related to NeoOffice. Probably you should reinstall or update NeoOffice? Or switch to OpenOffice?
    marek

  • I have got big problem. i have iphone 4 for a few day (it was new and packed) and now i realised that the screen during the conversation doen't block and turn up black. please help me, i don't knwo what to do!

    I've got big problem. i have iphone 4 for a few day (it was new and packed) and now i realised that the screen during the conversation don't block and turn up black. please help me, i don't knwo what to do!

    Connect to the Computer you Usually Sync with and Follow the Steps Here...
    Recovery Mode
    http://support.apple.com/kb/HT1808

Maybe you are looking for

  • Blank message when I send a video via a text message

    I got a replacement iPhone 4s last week.  Whenever I try and send a video (shot using the phone) via text message, the recipient (who uses an iPhone) gets a blank message, but are able to get pictures?  Do I need to check certain settings?

  • Purchase Requsition not shown in ASCP Workbench

    Hi All, We created an approved purchase requisition from ASCP one month back with three line items.This requisition is shown in ASCP workbench for 2 lines items as a supply but it is not showing as a supply in workbench for the other 1 item.Are there

  • Cases for the Iphone

    I know they moved the buttons a little but i want to know when cases come out because i myself am very clumsy and i dont want to drop the phone and break it. I checked online to see but most say Feb 10 they will come out with accessories i was wonder

  • Customize local layout in PO create

    Hi all, I created a SAP transaction iView for PO create. We have "Customize local layout"(It is the last one in the tool bar) option in ECC6.0. I couldn't able to get that option through iView. Do we need to make any setting changes or won't we get i

  • Where is the API for PKI authentication library in ColdFusion 9?

    Hello, I have to get PKI/certificates working with our ColdFusion application.  We're using CF9, and evidently there were calls added to this to help you get the cert, the distinguished name, etc.  So, what I am looking for specifically is where can