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