Communication between C ++ and Java, AEs/ECB/pkcs5padding

Source: Internet
Author: User

AES/ECB/pkcs5padding

 

C ++ does not seem to have such a standard, so if the program needs this format, you need to manually implement it.

In fact, there are a lot of resources in AES/ECB and C ++ on the Internet, that is, pkcs5padding. This can be achieved quite a little. The implementation principle is as follows:

AES is usually composed of 16 bytes and then encrypted. If the input string does not have 16 bytes, it must be supplemented,

Pkcs5padding: The filling principle is that if the length is less than 16 bytes, you need to fill up 16 bytes, fill (16-len) (16-len) for example:

The huguozhen character string is 9 bytes, 16-9 = 7. After it is filled up, for example, huguozhen + 7 decimal 7

If the string length is exactly 16 bytes, you need to add 16 bytes in decimal format.

 

The above is about encryption. For decryption, the strings to be decrypted are determined by byte. The specific principles are as follows:

Because the encryption is completed in decimal 1 to 16, during decryption, you need to remove this part of the complement to determine the string to be decrypted, whether each byte is Char> = 1 & char <= 16. If yes, use 0 to replace the previous value until the end.

 

Note that the C ++ string ends with a space.
Ayilian: After encryption, the first character is 0, that is, the subsequent string cannot be read. Therefore, in enbase64, you must specify the length and string pointer, do not just pass in the string pointer, so the encrypted value is null.

 

 

Hope to help you, if you have any questions, please contact me, guyuewuhua@163.com

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.