Terraria v1.4.4.9
Terraria source code documentation
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros

◆ ExportKeyBlob()

static byte[] System.Security.Cryptography.CngKeyLite.ExportKeyBlob ( SafeNCryptKeyHandle keyHandle,
string blobType )
inlinestaticpackage

Definition at line 58 of file CngKeyLite.cs.

59 {
60 global::Interop.NCrypt.ErrorCode errorCode = global::Interop.NCrypt.NCryptExportKey(keyHandle, IntPtr.Zero, blobType, IntPtr.Zero, null, 0, out var pcbResult, 0);
61 if (errorCode != 0)
62 {
63 throw errorCode.ToCryptographicException();
64 }
65 if (pcbResult == 0)
66 {
67 return Array.Empty<byte>();
68 }
69 byte[] array = new byte[pcbResult];
70 errorCode = global::Interop.NCrypt.NCryptExportKey(keyHandle, IntPtr.Zero, blobType, IntPtr.Zero, ref array[0], array.Length, out pcbResult, 0);
71 if (errorCode != 0)
72 {
73 throw errorCode.ToCryptographicException();
74 }
75 if (array.Length != pcbResult)
76 {
77 Span<byte> buffer = array.AsSpan(0, pcbResult);
78 byte[] result = buffer.ToArray();
79 CryptographicOperations.ZeroMemory(buffer);
80 return result;
81 }
82 return array;
83 }

References System.array, System.buffer, System.Span< T >.ToArray(), System.IntPtr.Zero, and System.Security.Cryptography.CryptographicOperations.ZeroMemory().

Referenced by System.Security.Cryptography.ECDiffieHellmanImplementation.ECDiffieHellmanCng.ExportFullKeyBlob(), System.Security.Cryptography.ECDsaImplementation.ECDsaCng.ExportFullKeyBlob(), System.Security.Cryptography.DSAImplementation.DSACng.ExportKeyBlob(), System.Security.Cryptography.ECDiffieHellmanImplementation.ECDiffieHellmanCng.ExportKeyBlob(), System.Security.Cryptography.ECDsaImplementation.ECDsaCng.ExportKeyBlob(), and System.Security.Cryptography.RSAImplementation.RSACng.ExportKeyBlob().