Create an unnamed CNG key through typed native helper

This commit is contained in:
Shirofune-Security committed 2026-09-21 17:53:39 +09:00
1 parent 718ef8c91d
commit 7184918f66
3 files changed
+10 -5

No files matched your search

+8
View File
@@ -2,9 +2,17 @@
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
namespace Wela.Capi2Probe {
public sealed class ChainResult { public uint Flags, ErrorStatus, InfoStatus, Chains, Elements; }
public static class Native {
public static CngKey CreateEphemeralRsa() {
CngKeyCreationParameters parameters=new CngKeyCreationParameters();
parameters.Provider=CngProvider.MicrosoftSoftwareKeyStorageProvider;
parameters.Parameters.Add(new CngProperty("Length",BitConverter.GetBytes(2048),CngPropertyOptions.None));
// Literal null is essential: PowerShell converts a null string argument to empty.
return CngKey.Create(CngAlgorithm.Rsa,null,parameters);
}
public const uint OfflineFlags=0x80002104; // cache-only URL/revocation, no AIA, no auth-root auto-update
[StructLayout(LayoutKind.Sequential)] struct Usage { public uint Count; public IntPtr Oids; }
[StructLayout(LayoutKind.Sequential)] struct Match { public uint Type; public Usage Usage; }