вторник, 30 сентября 2014 г.

Bouncy Castle and Crypto Pro. Detach signature from signed data.

In this post I will write how to:

1) detach signature that is attached to the data
2) view the content of signature.

Bouncy Castle is a good library but it is hard to find something in its documentation.

Here is the class that detaches the signature and writes the content of data to the File:

четверг, 25 сентября 2014 г.

Java zip file creation.

I had a task: get the files from database, create the zip file from them and serve the file to user.

The most tricky part of this process is to combine files into zip archive.

On my developer's computer I use windows 7  + Oracle JDK, on the test site we have Cent os and Websphere portal 7.

I have successfully wrote the code, tested it on developer's computer and deployed to test system. I have been surprised by the behavior of the code.
The code is as simple as:
 
ZipOutputStream zipStream = ...
ZipEntry zipEntry = new ZipEntry(zipEntryName);
zipStream.putNextEntry(zipEntry);
zipStream.closeEntry();
zipStream.finish();
zipStream.close();
 
My zip file contains entries made of Cyrillic symbols. But when I had got the file from test system I have found out that the filenames in zip archive have been corrupted.  On developer's computer everything worked fine.

The question is in encoding. I suggest that IBM JRE uses the system encoding for encoding the entry names in archive. Java 7 has the constructor
ZipOutputStream(OutputStream out, Charset charset) 
which accept charset for entry names encoding. But WebSphere Portal comes with java 6.

After googling I have found out the project Apache commons-compress project. It allows you to create zip files with specified zip entries encoding like the following:
zos = new ZipArchiveOutputStream(os);
zos.setEncoding("UTF-8");
zos.setFallbackToUTF8(true);
zos.setUseLanguageEncodingFlag(true);


Change the code to use commons-compress and I could produce identical results on developer's and test computers. Happy coding!

четверг, 18 сентября 2014 г.

Game Theory. An introduction.

I've had a vacation for a week and this time I have read the book "The Compleat Strategyst
Being a Primer on the Theory of Games of Strategy" by John D. Williams. You can find electronic version here

It is an introduction to the game theory and one of aims of the book was to popularize the subject. I can state that it can be understood by any who has a basic math knowledge. It also contains a lot of nice examples. It doesn't contain many theory and proves.

At least this book encourages me to do some research into how modern math programs like Maple, Mathematica have something about game theory. More is yet to come...

вторник, 9 сентября 2014 г.