Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Encrypt()

static unsafe void System.Security.Cryptography.AeadCommon.Encrypt ( SafeKeyHandle keyHandle,
ReadOnlySpan< byte > nonce,
ReadOnlySpan< byte > associatedData,
ReadOnlySpan< byte > plaintext,
Span< byte > ciphertext,
Span< byte > tag )
inlinestatic

Definition at line 29 of file AeadCommon.cs.

30 {
31 fixed (byte* pbInput = &GetNonNullPinnableReference(plaintext))
32 {
33 fixed (byte* pbNonce = &GetNonNullPinnableReference(nonce))
34 {
35 fixed (byte* pbOutput = &GetNonNullPinnableReference(ciphertext))
36 {
37 fixed (byte* pbTag = &GetNonNullPinnableReference(tag))
38 {
39 fixed (byte* pbAuthData = &GetNonNullPinnableReference(associatedData))
40 {
41 global::Interop.BCrypt.BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO bCRYPT_AUTHENTICATED_CIPHER_MODE_INFO = global::Interop.BCrypt.BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO.Create();
42 bCRYPT_AUTHENTICATED_CIPHER_MODE_INFO.pbNonce = pbNonce;
43 bCRYPT_AUTHENTICATED_CIPHER_MODE_INFO.cbNonce = nonce.Length;
44 bCRYPT_AUTHENTICATED_CIPHER_MODE_INFO.pbTag = pbTag;
45 bCRYPT_AUTHENTICATED_CIPHER_MODE_INFO.cbTag = tag.Length;
46 bCRYPT_AUTHENTICATED_CIPHER_MODE_INFO.pbAuthData = pbAuthData;
47 bCRYPT_AUTHENTICATED_CIPHER_MODE_INFO.cbAuthData = associatedData.Length;
48 int cbResult;
49 global::Interop.BCrypt.NTSTATUS nTSTATUS = global::Interop.BCrypt.BCryptEncrypt(keyHandle, pbInput, plaintext.Length, new IntPtr(&bCRYPT_AUTHENTICATED_CIPHER_MODE_INFO), null, 0, pbOutput, ciphertext.Length, out cbResult, 0);
50 if (nTSTATUS != 0)
51 {
52 throw global::Interop.BCrypt.CreateCryptographicException(nTSTATUS);
53 }
54 }
55 }
56 }
57 }
58 }
59 }
static unsafe ref readonly byte GetNonNullPinnableReference(ReadOnlySpan< byte > buffer)
int Length
Definition Span.cs:70

References System.Security.Cryptography.AeadCommon.GetNonNullPinnableReference(), System.ReadOnlySpan< T >.Length, and System.Span< T >.Length.

Referenced by System.Security.Cryptography.AesCcm.EncryptCore(), System.Security.Cryptography.AesGcm.EncryptCore(), and System.Security.Cryptography.ChaCha20Poly1305.EncryptCore().