diff --git a/src/Essensoft.Paylink.Security/AEAD_AES_256_GCM.cs b/src/Essensoft.Paylink.Security/AEAD_AES_256_GCM.cs index fd3884310..c1b486f7d 100644 --- a/src/Essensoft.Paylink.Security/AEAD_AES_256_GCM.cs +++ b/src/Essensoft.Paylink.Security/AEAD_AES_256_GCM.cs @@ -28,11 +28,16 @@ public static string Decrypt(string nonce, string ciphertext, string associatedD throw new ArgumentNullException(nameof(key)); } +#if NET8_0_OR_GREATER + var keyBytes = Encoding.UTF8.GetBytes(key); + using (var aesGcm = new AesGcm(keyBytes, 16)) +#else using (var aesGcm = new AesGcm(Encoding.UTF8.GetBytes(key))) +#endif { var nonceBytes = Encoding.UTF8.GetBytes(nonce); var ciphertextWithTagBytes = Convert.FromBase64String(ciphertext); // ciphertext 实际包含了 tag,即尾部16字节 - var ciphertextBytes = ciphertextWithTagBytes[0..^16]; // 排除尾部16字节 + var ciphertextBytes = ciphertextWithTagBytes[..^16]; // 排除尾部16字节 var tagBytes = ciphertextWithTagBytes[^16..]; // 获取尾部16字节 var plaintextBytes = new byte[ciphertextBytes.Length]; var associatedDataBytes = Encoding.UTF8.GetBytes(associatedData);