|
@@ -28,11 +28,16 @@ namespace Essensoft.Paylink.Security
|
|
|
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);
|