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

◆ Encrypt()

static int System.Net.Security.NegotiateStreamPal.Encrypt ( SafeDeleteContext securityContext,
ReadOnlySpan< byte > buffer,
bool isConfidential,
bool isNtlm,
[NotNull] ref byte[] output,
uint sequenceNumber )
inlinestaticpackage

Definition at line 60 of file NegotiateStreamPal.cs.

61 {
62 SecPkgContext_Sizes attribute = default(SecPkgContext_Sizes);
63 bool flag = SSPIWrapper.QueryBlittableContextAttributes(GlobalSSPI.SSPIAuth, securityContext, global::Interop.SspiCli.ContextAttribute.SECPKG_ATTR_SIZES, ref attribute);
64 int num = checked(2147483643 - attribute.cbBlockSize - attribute.cbSecurityTrailer);
65 if (buffer.Length > num)
66 {
67 throw new ArgumentOutOfRangeException("Length", System.SR.Format(System.SR.net_io_out_range, num));
68 }
69 int num2 = buffer.Length + attribute.cbSecurityTrailer + attribute.cbBlockSize;
70 if (output == null || output.Length < num2 + 4)
71 {
72 output = new byte[num2 + 4];
73 }
74 buffer.CopyTo(output.AsSpan(4 + attribute.cbSecurityTrailer));
75 ThreeSecurityBuffers threeSecurityBuffers = default(ThreeSecurityBuffers);
76 Span<SecurityBuffer> input = MemoryMarshal.CreateSpan(ref threeSecurityBuffers._item0, 3);
77 input[0] = new SecurityBuffer(output, 4, attribute.cbSecurityTrailer, SecurityBufferType.SECBUFFER_TOKEN);
78 input[1] = new SecurityBuffer(output, 4 + attribute.cbSecurityTrailer, buffer.Length, SecurityBufferType.SECBUFFER_DATA);
79 input[2] = new SecurityBuffer(output, 4 + attribute.cbSecurityTrailer + buffer.Length, attribute.cbBlockSize, SecurityBufferType.SECBUFFER_PADDING);
80 int num3;
81 if (isConfidential)
82 {
83 num3 = SSPIWrapper.EncryptMessage(GlobalSSPI.SSPIAuth, securityContext, input, sequenceNumber);
84 }
85 else
86 {
87 if (isNtlm)
88 {
89 input[1].type |= SecurityBufferType.SECBUFFER_READONLY;
90 }
91 num3 = SSPIWrapper.MakeSignature(GlobalSSPI.SSPIAuth, securityContext, input, 0u);
92 }
93 if (num3 != 0)
94 {
95 Exception ex = new Win32Exception(num3);
96 if (System.Net.NetEventSource.Log.IsEnabled())
97 {
98 System.Net.NetEventSource.Error(null, ex, "Encrypt");
99 }
100 throw ex;
101 }
102 num2 = input[0].size;
103 bool flag2 = false;
104 if (num2 != attribute.cbSecurityTrailer)
105 {
106 flag2 = true;
107 Buffer.BlockCopy(output, input[1].offset, output, 4 + num2, input[1].size);
108 }
109 num2 += input[1].size;
110 if (input[2].size != 0 && (flag2 || num2 != buffer.Length + attribute.cbSecurityTrailer))
111 {
112 Buffer.BlockCopy(output, input[2].offset, output, 4 + num2, input[2].size);
113 }
114 num2 += input[2].size;
115 output[0] = (byte)((uint)num2 & 0xFFu);
116 output[1] = (byte)((uint)(num2 >> 8) & 0xFFu);
117 output[2] = (byte)((uint)(num2 >> 16) & 0xFFu);
118 output[3] = (byte)((uint)(num2 >> 24) & 0xFFu);
119 return num2 + 4;
120 }
static readonly System.Net.NetEventSource Log
static void Error(object thisOrContextObject, FormattableString formattableString, [CallerMemberName] string memberName=null)
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string net_io_out_range
Definition SR.cs:30
Definition SR.cs:7

References System.Net.Security.ThreeSecurityBuffers._item0, System.Buffer.BlockCopy(), System.buffer, System.Net.SecPkgContext_Sizes.cbBlockSize, System.Net.SecPkgContext_Sizes.cbSecurityTrailer, System.Net.SSPIWrapper.EncryptMessage(), System.Net.NetEventSource.Error(), System.SR.Format(), System.input, System.Net.NetEventSource.Log, System.Net.SSPIWrapper.MakeSignature(), System.SR.net_io_out_range, System.offset, and System.Net.GlobalSSPI.SSPIAuth.

Referenced by System.Net.NTAuthentication.Encrypt().