Base64 En-/Decoding using OpenSSL in C

IT, UNI Kommentare deaktiviert

Recently i had to implement Base64 en & decoding using openssl’s bio library, which by the way is just great, but a little “under-documented!”

If you ever wondered, why the standard example of decoding base64 data always returns 0 when using it with your test data? Well there is some nice undocumented feature: Strings that do not end with a newline ‘\n’ are not processed! So you have two possibilities: adding a newline to the string or use the following flag:

BIO_set_flags(BIO* to your bio_f_base64, BIO_FLAGS_BASE64_NO_NL);

Edit: 21/Dec/08:

After handin of the courses homework i can now give some details about how to do it:

Using a chain of BIO filters is the most flexible way to handle proper base64 en-/decoding:


//write base64 coded data to stdout
BIO* b64 = BIO_new(BIO_f_base64());
BIO* bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
bio_out = BIO_push(b64, bio_out); //attach output bio to base64 bio
BIO_write(bio_out,"data",sizeof("data"));
BIO_flush(bio_out); //flush the buffer
BIO_free_all(bio_out); //cleanup!

For more information see the super perfect documentation: http://www.openssl.org/docs/crypto/BIO_f_base64.html

Accessing Matlab from Java

IT Kommentare deaktiviert

Today i had to access a matlab script from a java program. After some hours of trying to get it work by using matlabs command line i found a method to call a matlab script without using the command line. Using matlab -r “functionName” didn’t work because of some unknown charset erros i haven’t found till now. The basic idea is based on this blog-post.

Therefore, a process must be created:


String command = "matlab -nosplash -nodesktop";
Process process = Runtime.getRuntime().exec(command);

Afterwards we obtain the standard-input of the process and send a command to be interpreted by matlab:


BufferedWriter out = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
out.write("function_to_be_executed");
out.write("\n");
out.write("exit;") // this will close matlab after the execution finished!

If you like to see what is happening, try to read from the process.getInputStream()

hope that helps some of you!

X: Multiple Monitors with different solutions

Linux Kommentare deaktiviert

Today i found a solution to use both my notebooks display [1440x800] (Dell Vostro 1510 with NVidia 8400M GS) and my flatpanel tft [1280x1024] under Ubuntu 8.04.

This is what my xorg.conf looks like (only the important parts!)

Section “Screen”
Identifier “Default Screen”
Device “nVidia Corporation G80 [GeForce 8400M GS]”
Monitor “Generic Monitor”
DefaultDepth 24
Option “TwinView”
Option “MetaModes” “1440×900 1280×1024″
Option “TwinViewOrientation” “LeftOf”
SubSection “Display”
Modes “1440×1440″
EndSubSection
EndSection

Section “Screen”

# Removed Option “metamodes” “CRT: nvidia-auto-select +1440+0, DFP: nvidia-auto-select +0+0″
Identifier “Screen0″
Device “Videocard0″
Monitor “Monitor0″
DefaultDepth 24
Option “TwinView” “1″
Option “TwinViewXineramaInfoOrder” “DFP-0″
Option “metamodes” “CRT: 1280×1024 +1440+0, DFP: nvidia-auto-select +0+0″
EndSection

This config was partially done using: nvidia-settings (apt-get install nvidia-settings)

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS