How to decode a base64 string with OpenSSL library

OpenSSL library works with base64-encoded strings as a part of its public keys infrastructure, for example. That means, it has base64 encoding and decoding. The other thing is, if is it possible and if is it easy to utilize that encoding. We found it is possible, but it has some unexpected issue.

The thing is (and it was determined while debugging under Microsoft Visual C++), when static function b64_read() in bio_b64.c works, it looks for a ‘\n’ character in text and does decoding only if this symbol exists.

As base64 decoding function in any application is usually called many times, we propose to implement it as a function:

vector<uint8_t> Base64toBin(const char* strBase64)
{
	BIO *bio, *b64;
	int inlen;	
	uint8_t inbuf[512];

	b64 = BIO_new(BIO_f_base64());
	string tmpString = strBase64;
	if (tmpString.find('\n') == string::npos)
		tmpString = tmpString + "\n";
	bio = BIO_new_mem_buf(tmpString.c_str(), tmpString.size());
	BIO_push(b64, bio);
	
	vector<uint8_t> res;

	while ((inlen = BIO_read(b64, inbuf, 512)) > 0)
	{
		for (int i = 0; i < inlen; i++)
		{
			vector<uint8_t> tmp(1, inbuf[i] );
			res = res + tmp;
		}	
	}
	BIO_free_all(b64);
	return res;
}


Continue reading

How to get OpenSSL sources with Git and compile them for Windows with MS Visual Studio tools

We need quite a few tools to perform the task of obtaining OpenSSL’s binary files from its sources. Let us start with getting Git client. There is much different software in that area. We chose GitHub Desktop from https://desktop.github.com/.  It has both graphic and console interfaces. We will use console version, which is called Git Shell. When we start it, we get a command line, where input next instruction:

cd c:\

Now we can download the source with the help from https://www.openssl.org/source/gitrepo.html manual. We will download stable branch (or version). For now, it is 1.1.0, so we call the instruction:

git clone git://git.openssl.org/openssl.git -b OpenSSL_1_1_0-stable

We obtain messages:
Continue reading

Android in IntelliJ IDEA development story

For a fair amount of time, I thrive to do something for Android. Some funny genius staff, as I usually like to. I’ve tried Android Studio 2.1.something, pecked at it a little, tried several lessons and put it aside. While installing I hit the bug with a non-ASCII path to installation, reinstalled several times. At some point a had to clean up my system (Windows 7) and reset entire notebook to its factory settings. Then I installed Android Studio again, worked with it little more, installed concurring IntelliJ IDEA, worked in it without Android.

They periodically updated, I added SDKs and virtual devices and for yesterday I had a unmaintainable chunk of installations, where I did not know, what uses what, with probable duplications and dead data. Unable to run debug on a virtual device for IntelliJ IDEA, I uninstalled all I could and deleted the rest. All Android, all Android SDK and so on. It freed me about 50 GB of space. Fifty OMG GB!

Now I chose to use IntelliJ IDEA only, so I went by steps from manual carefully avoiding any space-wasting.
Continue reading

Git and Dropbox. Pitfall.

When you develop an application, you are interested in version control. It is a wicked technique to spawn folders project-0.1.87, project-0.1.88-test and so on. If it is a technique at all and not a complete absence of any. Besides, you, probably want to have your code on the internet on deep raided servers with 24/7 maintenance in case your computer (Got forbid!) says ‘Goodbye’. You may want to invite somebody to take part in your work sometime later. So, organize local version control would not so foresee option.

The good news is that you can use GitHub. The bad news — everybody will see you little private projects and steal your brilliant business ideas. The good news again is that there is a Dropbox. There you can get about 2GB of disk space for free and a bit more for some efforts or money. But Git will help. Dropbox or not — we want to enforce control version nonetheless.

So, you need to install GitHub’s client. Or any Git client. The one you love will do, perhaps. Then, in its shell you run next magic commands:


~/project $ git init
~/project $ git add .
~/project $ git commit -m "first commit"
~/project $ cd ~/Dropbox/git

~/Dropbox/git $ git init --bare project.git
~/Dropbox/git $ cd ~/project

~/project $ git remote add origin ~/Dropbox/git/project.git
~/project $ git push -u origin master

I personally have done something like that and had some errors in last push command. The problem is explained below page from StackOverflow, but most manuals I’ve seen leaves you in the wrong place. The decision is to make some file and add it with something like that:

$ git add somefile.txt
$ git commit –m “Created some file”

Then you are doing push. Command shell will prompt you the correct first push format. Good luck!