Hi Lei,

After base64 encoding, there are characters (+/=) not allowed for PI
target. I suggest two ways:
1. separate your processing instruction to two parts:
    doc.createProcessingInstruction("DigSign", encodedSig) );
2. use Hex encoding (which only uses A~F 0~9, but waste some space) instead
of base64. It would be very easy to implement.

HTH,
Sandy Gao
Software Developer, IBM Canada
(1-416) 448-3255
[EMAIL PROTECTED]



                                                                                
                                    
                    Lei Chen                                                    
                                    
                    <[EMAIL PROTECTED]       To:     "'[EMAIL PROTECTED]'" 
<[EMAIL PROTECTED]>   
                    merce.com>            cc:                                   
                                    
                                          Subject:     RE: embed digital 
signature in XML                           
                    04/02/2001                                                  
                                    
                    04:02 PM                                                    
                                    
                    Please respond                                              
                                    
                    to                                                          
                                    
                    xerces-j-user                                               
                                    
                                                                                
                                    
                                                                                
                                    




I tried both encode(byte[]) and encodeBuffer(byte[]) of
sun.misc.BASE64Encode, but I am still getting the same exception. Here is
the code:

                  byte[] data = ...
                  byte[] sig = signature.sign(data);
                   ...
                   Element root = doc.createElement("top");
                   doc.appendChild(root);
                   ...
                  sun.misc.BASE64Encoder encoder = new
sun.misc.BASE64Encoder();
                  String encodedSig = encoder.encodeBuffer(sig);
                   root.appendChild (
doc.createProcessingInstruction("DigSign" + encodedSig, null) );
What kind of character is allowed in processing instructions?

-Lei

     -----Original Message-----
     From: Mark Sizer [mailto:[EMAIL PROTECTED]
     Sent: Monday, April 02, 2001 12:18 PM
     To: '[EMAIL PROTECTED]'
     Subject: RE: embed digital signature in XML

     I base64 encode my digital signatures before stuffing them into XML -
     it works fine.

     I'm using an open-source package from Germany, but I believe there is
     a base64 encoder/decoder buried in the Xerces packages somewhere. If
     not, Sun has one, too.
          -----Original Message-----
          From: Lei Chen [mailto:[EMAIL PROTECTED]
          Sent: Monday, April 02, 2001 9:42 AM
          To: '[EMAIL PROTECTED]'
          Subject: embed digital signature in XML

          Hi folks,

          I am trying to embed a digital signature into a XML document as
          processing
          instructions like following:

                            <top>
                                <contract>
                                      ...
                                </contract>
                                <?DigSignA234B5678E897?>
                             </top>

          The signature was generated by using 'byte[] Signature.sign(bye
          [])' from
          java.security package. However, when I ran following code:

                            ...
                            byte[] data = ...
                            byte[] sig = signature.sign(data);
                             ...
                             Element root = doc.createElement("top");
                             doc.appendChild(root);
                             ...
                             root.appendChild (
          doc.createProcessingInstruction("DigSign" + new String(sig),
          null) );
          I got
          java.lang.InstantiationError: org/w3c/dom/DOMException
           at
          
org.apache.xerces.dom.DocumentImpl.createProcessingInstruction(DocumentImpl.java:566)
          If I switch to sun's crimson parser, the error message is more
          informative:
          org.apache.crimson.tree.DomEx: INVALID_CHARACTER_ERR: An invalid
          character was specified, such as in a name.
           at
          
org.apache.crimson.tree.XmlDocument.createProcessingInstruction(XmlDocument.java:984)


          I guess some kind of encoding has to be done to the signature
          byte array before I construct the
          String and pass it to this method. But I don't know how to do it.
          Can somebody point it out?

          thanx in advance
          -Lei







---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to