Test PaddedBufferedBlockCipher with AES and PKCS7 padding.
1 import dcrypt.blockcipher.padding.pkcs7; 2 import dcrypt.blockcipher.aes; 3 4 PaddedBufferedBlockCipher!(AES, PKCS7Pad) c; 5 6 immutable ubyte[] key = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; 7 ubyte[] plain = new ubyte[65]; 8 ubyte[] output = new ubyte[96]; 9 10 foreach(plainTextLength; [0,1,15,16,17,24,31,32,33,63,64,65]) { // some odd number, smaller than one block, larger than two blocks 11 12 plain.length = plainTextLength; 13 14 foreach(i,ref b; plain) { 15 b = cast(ubyte)i; 16 } 17 18 output.length = ((plainTextLength/c.blockSize)+2)*c.blockSize; // next even block size 19 20 c.start(true, key); 21 22 size_t len = c.processBytes(plain, output); 23 len += c.doFinal(output[len..$]); 24 output = output[0..len]; // crop slice to its size 25 26 ubyte[] cipher = output.dup; 27 output[] = 0; 28 c.start(false, key); 29 len = c.processBytes(cipher, output); 30 len += c.doFinal(output[len..$]); 31 32 assert(len == plain.length, "length does not match"); 33 assert(output[0..len] == plain, "decrypted ciphertext is not equal to original plaintext"); 34 }
test if T is a block cipher padding