encrypt-decrypt single block with AES and Crypto++

戏子无情 提交于 2019-12-01 21:13:45

问题


I need to encrypt single block of AES. I cant use any modes like CBC and other. Every example what i have seen use streaming modes.

EDIT: ok, i did it in the next manner, but i really dislike this try.

void dec(const byte *key, const byte* xblock, const byte *cipher, byte *plain) {
    AESDecryption d;

    try {
        const NameValuePairs &nvp = MakeParameters("", 0);
        d.UncheckedSetKey(key, 16, nvp);
        d.ProcessAndXorBlock(cipher, xblock, plain);
    }
    catch(...) {}
}

回答1:


AES in ECB mode is identical to single block encryption, except that you can feed it multiple blocks.

If you've got only CBC mode encryption available you can use the first block of a CBC encrypt using a (block sized) IV containing bytes all valued zero. The same goes for counter (CTR) mode encryption and a nonce containing bytes all valued zero (the counter only increases after the first block encrypt).

Crypto++ seems to be a higher level Crypto API, so it is better not to directly call the AES implementation directly.



来源:https://stackoverflow.com/questions/11082432/encrypt-decrypt-single-block-with-aes-and-crypto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!