Announcing TitaniumD - A D Binding for the Botan Cryptography Library

Adam Wilson via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Thu May 1 15:58:31 PDT 2014


On Thu, 01 May 2014 14:55:05 -0700, brad clawsie <brad at b7j0c.org> wrote:

> Adam, this is very cool!
>
> do you have any examples showing its use? In particular, examples  
> highlighting D code using AES and SHA libs
>
> thanks!
> brad

You're welcome. There are no example yet. And the build script only  
supports Windows. Pull requests using *make tools most welcome.

A little walkthrough:

Build TitaniumCore, TitaniumD and TDI as static libraries. TitaniumCore  
and TitaniumD can be compiled with any C++ compiler and the availability  
of Boost Filesystem and ASIO. Although you'll have to specify the paths to  
Boost.

Once those libraries are built you'll need to pass all three of them to  
DMD along with your project.

Then the following code should work:

module test;
import std.stdio;
import Titanium.TDI; //Make sure to specify the correct search path with  
-I on the DMD commandline.

void main(string[] args)
{
	auto t = new TitaniumLibrary();
	//Hash Test Vectors
	string vec1 = "The quick brown fox jumps over the lazy dog";
	string vec2 = "The quick brown fox jumps over the lazy dog.";
	//Hash Testing
	writeln(HashSHA2(HashSize.Size256, vec1));
	SHA2 h = new SHA2(HashSize.Size256);
	writeln(h.Process(vec2));
	AES c = new AES(CipherKeySize.Key128, CipherMode.GCM, 16);
	ubyte[] enc1 = c.Encrypt(cast(ubyte[])vec1.dup);
	string dec1 = cast(string)c.Decrypt(enc1);
	ubyte[] enc2 = c.Encrypt(cast(ubyte[])vec2.dup);
	string dec2 = cast(string)c.Decrypt(enc2);
	writeln(enc1);
	writeln(dec1);
	writeln(enc2);
	writeln(dec2);
}

The above sample shows SHA2 and AES-128/GCM.

Please submit bug reports and pull requests on GitHub if you run into any  
problems!

-- 
Adam Wilson
IRC: LightBender
Project Coordinator
The Aurora Project


More information about the Digitalmars-d-announce mailing list