AES ECB PKCS7 Decryption problem

Source: Internet
Author: User

AES decryption is used in the recent project. Because the interface provided by the customer is encrypted by AES.

A problem was found during the decryption process. The direct decryption of the words to solve the data is not correct, so the original string needs to do some operations and decryption.

Turn 16 binary value to byte[]

AES Decryption
</summary>
<param name= "Encryptstr" > Ciphertext string </param>
<returns> Clear </returns>
public static byte[] Aesdecrypt (string encryptstr)
{
Encryptstr = Encryptstr.replace ("\ r \ n", ""); Replace swap line symbol
Byte[] keys = Encoding.UTF8.GetBytes ("secret key");
Byte[] by = new BYTE[ENCRYPTSTR.LENGTH/2];
int j = 0;
for (int i = 0; i < encryptstr.length; i = i + 2)
{
BY[J] = Convert.tobyte (Encryptstr.substring (i, 2), 16);
j + +;
}
Return AES. Decrypt (keys, by);
}

AES ECB PKCS7 Decryption problem

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.