AES ECB encrypt/decrypt only decrypts the first 16 bytes

后端 未结 2 1627
囚心锁ツ
囚心锁ツ 2020-12-20 22:42

I had function that decode AES 256 string but it return only 16 char

bool decrypt_block(unsigned char* cipherText, unsigned char* plainText, unsigned char* k         


        
2条回答
  •  执笔经年
    2020-12-20 23:00

    It appears that you are confusing key length and block size.

    AES can be used with 3 different key lengths: 128-bits, 192-bits & 256-bits.

    AES always uses a block size of 128 bits (16 bytes). For messages that are more than 16 bytes long, you need to decrypt (or encrypt) 16 bytes at a time and expect to get 16 bytes of output each time. (You will also need to decide which mode to use - e.g. CBC, CTR, ECB, etc.. If you're decrypting text provided by somebody else then that decision has already been taken for you. If making the decision for yourself, bear in mind that ECB is almost never the right choice.) If the message isn't a multiple of 16 bytes long, you'll need to pad it so that it is. PKCS #7 padding is the most common.

    See the Wikipedia article on AES for more information.

提交回复
热议问题