AES 256 encryption - Qt equivalent for Java

前端 未结 2 1165
情话喂你
情话喂你 2021-01-03 03:21

I have my AES 256 encryption method implemented and working fine in Java as follows!

  private static final byte[] IV = {
    0, 2, 4, 8, 16, 32, 64, 127, 
          


        
2条回答
  •  半阙折子戏
    2021-01-03 03:28

    Initialization vector is different in your Java code and Qt:

    private static final byte[] IV = {
        0, 2, 4, 8, 16, 32, 64, 127, 
        127, 64, 32, 16, 8, 4, 2, 0
    };
    

    And in C++:

    memset( iv, 0x00, AES::BLOCKSIZE ); // ==> This fills the iv array with 0s
    

    So you need to use same IV for both schemes.

    Update:

    In order to provide an IV for CBC mode of AES, you need to specify IV as you do in Java:

    byte iv[ AES::BLOCKSIZE ] = {0, 2, 4, 8, 16, 32, 64, 127, 
                                 127, 64, 32, 16, 8, 4, 2, 0};
    

    Note that AES::BLOCKSIZE is defined in library headers and it is 16.

提交回复
热议问题