GcryptNoIV.decrypt

Decrypt the content of buffer in place.

class GcryptNoIV(Algorithm algorithm, Mode mode)
void
decrypt

Parameters

buffer mstring

the content to be decrypted in place

Throws

if the decryption fails

Examples

Test encrypting and decrypting a short value.

auto key = generateKey();

auto crypt = new typeof(this)(key);

auto original = generateMessage();
mstring buf;
buf ~= original;

// Encrypt buf in place
crypt.encrypt(buf);
test!("!=")(buf, original);

// Decrypt buf in place
crypt.decrypt(buf);
test!("==")(buf, original);

Test that encrypting a value after setting an IV gives the same result as not setting an IV. For these algorithms, the IV should not be used.

auto key = generateKey();

auto crypt = new typeof(this)(key);

auto original = generateMessage();
mstring buf;
buf ~= original;

// Encrypt buf in place
crypt.encrypt(buf);

// Generate and set an IV
auto iv = generateMessage();
gcry_cipher_setiv(crypt.handle, iv.ptr, iv.length);

// Encrypt another buf in place and test that is the same as before
mstring buf2;
buf2 ~= original;
crypt.encrypt(buf2);

test!("==")(buf, buf2);

Meta