crypto 0.2.6

A D Library of encrypto, decrypto(3DES, AES, TEA, RSA...), encode, hash, and message digital signatures.


To use this package, put the following dependency into your project's dependencies section:

dub.json
dub.sdl

Build Status GitHub tag

A D Library of encryption, decryption, encode, hash, and message digital signatures.

The same functional and fully compatible C++ project: https://github.com/shove70/shove.c

AES:

import crypto.aes;
import crypto.padding;

string key = "12341234123412341234123412341234";
ubyte[] message = cast(ubyte[])"123412341234123412341234123412341";
ubyte[] iv = [1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 1, 2, 3, 4];

ubyte[] buffer = AESUtils.encrypt!AES128(message, key, iv, PaddingMode.PKCS5);
buffer = AESUtils.decrypt!AES128(buffer, key, iv, PaddingMode.PKCS5);

assert(message == buffer);

XTEA:

import crypto.tea.xtea;
import crypto.padding;

int[4] key = [1, 2, 3, 4];
int rounds = 64;
ubyte[] message = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];

ubyte[] buffer = Xtea.encrypt(message, key, rounds, PaddingMode.PKCS5);
buffer = Xtea.decrypt(buffer, key, rounds, PaddingMode.PKCS5);

assert(message == buffer);

RSA:

import crypto.rsa;

RSAKeyPair keyPair = RSA.generateKeyPair(1024);
writeln(keyPair.privateKey);
writeln(keyPair.publicKey);

string data = "Data that needs to be encrypted";

ubyte[] en = RSA.encrypt(keyPair.privateKey, cast(ubyte[])data);
ubyte[] de = RSA.decrypt(keyPair.publicKey, en);
writeln(cast(string)de);

assert(cast(string)de = data);

Thanks

  • @n8sh
  • @Boris-Barboris

Other

For more examples, see unittest, Thanks.

Authors:
  • Shove
Dependencies:
none
Versions:
0.2.6 2019-Jul-12
0.2.5 2019-Jul-08
0.2.4 2019-Jun-18
0.2.3 2019-Jun-04
0.2.2 2019-May-28
Show all 17 versions
Download Stats:
  • 0 downloads today

  • 47 downloads this week

  • 85 downloads this month

  • 8092 downloads total

Score:
2.6
Short URL:
crypto.dub.pm