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

◆ UnloadKey()

static void Internal.NativeCrypto.CapiHelper.UnloadKey ( SafeProvHandle hProv,
SafeKeyHandle hKey,
[NotNull] ref byte[] key_out,
ref int cb_out )
inlinestaticprivate

Definition at line 1246 of file CapiHelper.cs.

1247 {
1248 SafeKeyHandle phKey = null;
1249 try
1250 {
1251 if (!CryptImportKey(hProv, RgbPubKey, SafeKeyHandle.InvalidHandle, 0, out phKey))
1252 {
1253 int hRForLastWin32Error = Marshal.GetHRForLastWin32Error();
1254 throw hRForLastWin32Error.ToCryptographicException();
1255 }
1256 int dwDataLen = 0;
1257 if (!global::Interop.Advapi32.CryptExportKey(hKey, phKey, 1, 0, null, ref dwDataLen))
1258 {
1259 int hRForLastWin32Error2 = Marshal.GetHRForLastWin32Error();
1260 throw hRForLastWin32Error2.ToCryptographicException();
1261 }
1262 byte[] array = new byte[dwDataLen];
1263 if (!global::Interop.Advapi32.CryptExportKey(hKey, phKey, 1, 0, array, ref dwDataLen))
1264 {
1265 int hRForLastWin32Error3 = Marshal.GetHRForLastWin32Error();
1266 throw hRForLastWin32Error3.ToCryptographicException();
1267 }
1268 int num = 8;
1269 int num2 = num + 4;
1270 int num3 = checked(dwDataLen - num - 4 - 2);
1271 while (num3 > 0 && array[num3 + num2] != 0)
1272 {
1273 num3--;
1274 }
1275 key_out = new byte[num3];
1276 Buffer.BlockCopy(array, num2, key_out, 0, num3);
1277 Array.Reverse(key_out);
1278 cb_out = num3;
1279 }
1280 finally
1281 {
1282 phKey?.Dispose();
1283 }
1284 }
static ReadOnlySpan< byte > RgbPubKey
Definition CapiHelper.cs:31
static unsafe bool CryptImportKey(SafeProvHandle hProv, ReadOnlySpan< byte > pbData, SafeKeyHandle hPubKey, int dwFlags, out SafeKeyHandle phKey)
static void Reverse(Array array)
Definition Array.cs:2207
static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
Definition Buffer.cs:102

References System.array, System.Buffer.BlockCopy(), Internal.NativeCrypto.CapiHelper.CryptImportKey(), System.Runtime.InteropServices.SafeHandle.Dispose(), System.Runtime.InteropServices.Marshal.GetHRForLastWin32Error(), System.Array.Reverse(), and Internal.NativeCrypto.CapiHelper.RgbPubKey.

Referenced by Internal.NativeCrypto.CapiHelper.DeriveKey().