使用AES和Crypto ++加密 - 解密单个块 [英] encrypt-decrypt single block with AES and Crypto++

查看:429
本文介绍了使用AES和Crypto ++加密 - 解密单个块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要加密AES的单个块。我不能使用任何模式像CBC和其他。每个例子我看到使用流模式。

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.

编辑:
ok,我做了下一个方式,但我真的不喜欢这个尝试。 p>

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(...) {}
}


推荐答案

AES在ECB模式下与单块加密相同,只是您可以提供多个块。

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

只有CBC模式加密可用,你可以使用CBC加密的第一块使用(块大小)IV包含字节,所有值为零。对于计数器(CTR)模式加密和包含字节的所有值都为零(计数器仅在第一个块加密之后才增加)的情况下也是如此。

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 ++似乎是更高级别的Crypto API,因此最好不要直接调用AES实现。

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

这篇关于使用AES和Crypto ++加密 - 解密单个块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆