Jiri Nejedly

Ranch Hand
+ Follow
since Oct 22, 2002
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jiri Nejedly

Hello, in work I sort of inherited a java code after my predecessor, which signs the PDF file by certificate. One small flaw it has - the ceftificate icon is placed randomly (?) in PDF file.
I found out that the important code is this:

l also googled , that this method exists, but we don't use it

I was never able to find out what location (string type) means.
We use Jasper reports for making PDFs, but fields have names only in templates. The final PDF has not that information.
Or am I wrong and I must place 'something' to the template so the final PDF would know where to put the sign?


3 days ago
Unfortunately stack doesn't give line numbers. First line is the line in our code (open method) :
8 months ago
Hi . we are authors of software, which posts some data to some goverment portal. Part of posting is signing the data by certificate (.pfx). Customer's certificate expires in a few days so he bought a new one.
there are 2 differences between old and new -  3 year life span instead of one year and the new is "CA 4" instead of "CA 3"'
Our main problem is that this code (see load...) fails with the new certicate:

Strange exception ArrayIndexOutOfBoundsException 0 >= 0 is issued.
Bouncy castle version is 1.38.
Another problem is that customer wont't give us the new certificate for testing.

Any idea what might be wrong? Thanks.
8 months ago
Finally I googled a solution. The trick is that I must setup a simple http server inside my app to provide streaming access to the videos.
9 months ago
Hi. I am novice in Android development. For now, I am trying to understand and modify various example applications. I found 'CastVideos-android-master' sample application, which can cast some predefined and stored somwhere videos to Chromecast. But I am not able to find any example or principle explanation, which allows to cast local video(s). I understand that in first case Chromecatest gets only url of the video and 'plays it itself'. But local video? I searched high and low but didn't found anything. I myself used DrectCast app, which is unfortunatelly discontinued and not working on my android version and now i use BubbleUPnP, which is good but too complex. My need is to cast playlists of music videos stored on external card and manage those playlists. So I would try to create it myself. Thanks for any suggesions.
9 months ago
I finally googled the solution (BouncyCastle library). The JcaPEMWriter class did the trick.  

1 year ago
Thanks, but it will be tough to understand it all... I rather learn by examples

But I have just one more question - above i wrote, that I am building some xml containing public key (base64) of my certificate. Something such as

And how am I getting the data for this tag? So far manually.
I found the certificate among other personal ones in Chrome browser.
Exported it into file, without private key, X.509, coding Base-64 (CER).
Then opened the exported file in the text editor, removed '-----BEGIN CERTIFICATE-----'
and '----END CERTIFICATE-----''and the rest put into XML

This all I need to repeat by java code. I think it will be easy,
but the examples are scarce.


1 year ago
I finally googled the solution using the BouncyCastle library

But one question regarding the above code remains, the collection 'recipients' in my case has 2 items.
First fetched (next) KeyTransRecipientInformation ends with exception
org.bouncycastle.cms.CMSException: exception unwrapping key: bad padding: Decryption error
When I fetch the second, the decryptedData are finally ok.
Can I somehow find out which recipient is the right one, before I invoke the exception ?

Thanks, JN

1 year ago

I'm working on project which collect data from some government portal.

To obatain valid data I had to make rerequest containing some exact xml data.
The xml data had also to contain public key of my certificate. The the portal then encrypts  
the returned data. With the the returned data I am expected to do the following:

1. Decode the xml element data from Base64 to array of bytes
- I did it. I got some binary data. I even see the "PostSignum Public CA 4" among the bytes.

2. Decrypt it according to CMS/PKCS #7 standard

3. Decompress it in gzip format

I am not able to do the second part. I googled all over, bud didnt't find anything working.
I know, how to get the certificate, the private key, the alias, but at this point my knowledge ends.

Would somebody be so kind and provide some working example, regarding decrypting pkcs#7 standard ?

1 year ago
I tried the Dox4J library and found the solution

The code is pretty easy

1 year ago
There is no way to make zip (docx) manually. I tried to save XML template as DOCX and analyze it as ZIP. It contains 22 (!) files, mostly XML but also a picture (customer's logo). To find out what are all files meant for is unreal task.
1 year ago
Maybe it would be better to describe the whole problem at large:

Our application cat output data as reports in various formats using Jasper server.
There is no way to learn our customers how to edit .jrxml templates.

MS Word is rather different. Customers know MS Word and would like to modify the reports according to their needs.
So we created this solution for them:

- We give them predefined XML Word Template(s). On it we put dynamic text words such as %001, %002, %003,...
- Those words will be dynamically substituted by data obtained from sql query. Query always returns only one row.
- Those data are already formatted inside sql (date formats, decimal places,...)
- First value from query row substitues string %001, second %002 and so on
- We don't want to change the XML structure! Substitution is meant to be a simple string replacement
- Our customers then can edit those xml templates in MS Word. Only they must leave the the substitution words
%001, %002, %003... as they are. Other text they can freely edit.

And the problem is this - though we see the string '%001' on template, it doesn't mean it is stored in xml as string
'%001' but is probably divided by formatting tags. I see 2 solutions
- When making teplates we must check every substitute words that resulting xml contains it undivided. If not, we must reformat
it or better retype it
- Write a smart replace algorithm which finds and replaces sustitution words even if they are divided.
But never change formating tags.

I can imagine that algorithm without parsing xml , just scanning xml as string. I just asked if anybody encountered the same problem. I see probably not.
1 year ago
This is just an example. The real data (substiton string is '%009') looks like this

...<w:t>%0</w:t></w:r><w:r w:rsidR="00C113C5"><w:rPr><w:rFonts w:cs="Arial"/><w:b/><w:color w:val="000000"/><w:sz w:val="20"/><w:szCs w:val="20"/><w:lang w:val="en-US"/></w:rPr><w:t>09</w:t>...

so our goal is this

...<w:t>%009</w:t></w:r><w:r w:rsidR="00C113C5"><w:rPr><w:rFonts w:cs="Arial"/><w:b/><w:color w:val="000000"/><w:sz w:val="20"/><w:szCs w:val="20"/><w:lang w:val="en-US"/></w:rPr><w:t></w:t>...
1 year ago
Is there any java way (library ?) of converting MS Word XML (template) to DOCX ? Our java application opens XML template , feeds a data in it and saves it again as .xml file.
But our customers must associate the xml with MS Word application. To avoid the association, we would like to give them the DOCX file right away.
Any ideas? Thanks
1 year ago

we use Word xml templates. We would like to replace predefined words by user text obtained from database.
But there's problem - the text to substitute e.g. "%001", can be in xml source sparated by formatting tags. Something like this


We would like to have special replace algorithm which can find the above tag separated text and replace it this way:


Does anybody have an idea how to do it ?
We don't want to parse the whole document even if it is valid xml.
1 year ago