1. Resources
  2. Detection sources
  3. Event ID 5058

Event ID 5058: Key file operation

Written when a key file of the Microsoft Software or Smart Card Key Storage Provider is read, written or deleted, with the account, key name and path. On a CA server it shows who opened the CA's key file, next to the exports 5059 records.

Log source
Windows Security log
Detection value
Context
Volume
Low
Last updated
Audit subcategory
Audit Other System Events (System, Success and Failure)
Logged on
All Windows computers
Event versions
0, 1
Detects
Not read by our detection rules yet

When it is written

Windows writes 5058 when an operation such as a read, a write or a deletion is performed on a file that holds a key of a CNG key storage provider (KSP), if Audit Other System Events is on. As with 5059, Microsoft says only two providers write it: the Microsoft Software Key Storage Provider and the Microsoft Smart Card Key Storage Provider. Microsoft gives certificate renewal and certificate export as examples of activity that produces it.

A successful operation has Return Code 0x0; a failed one is an Audit Failure event with the error code. Every role writes it: domain controllers, member servers and workstations, for the keys stored on that computer.

How to turn it on

Advanced audit policy subcategory Audit Other System Events, Success and Failure. Set it in a Group Policy object linked to the computers that write the event:

Computer Configuration > Policies > Windows Settings > Security Settings > Advanced Audit Policy Configuration > Audit Policies > System > Audit Other System Events
Microsoft's recommendation per computer role
ComputerAuditNote
Domain controllersSuccess and FailureRecommended in both baselines, for the start, stop and failure events of the Windows Firewall service and driver.
Member serversSuccess and FailureRecommended in both baselines, for the start, stop and failure events of the Windows Firewall service and driver.
WorkstationsSuccess and FailureRecommended in both baselines, for the start, stop and failure events of the Windows Firewall service and driver.
Check the current setting
auditpol /get /subcategory:"Other System Events"
Based on vendor documentation.
Turn it on (local policy; a domain GPO overrides it)
auditpol /set /subcategory:"Other System Events" /success:enable /failure:enable
Based on vendor documentation.
The same on a Windows in another display language
auditpol /get /subcategory:"{0CCE9214-69AE-11D9-BED3-505054503030}"
Based on vendor documentation.

Run the commands in an elevated prompt on a computer that writes the event. Subcategory settings take effect only when the security option Audit: Force audit policy subcategory settings (Windows Vista or later) to override audit policy category settings is enabled (the default), and a Group Policy object that sets advanced audit policy replaces local changes at its next refresh. Microsoft's advanced audit policy reference

The subcategory is not enough on its own. Microsoft documents 5058 only for keys held by the Microsoft Software Key Storage Provider or the Microsoft Smart Card Key Storage Provider. A key held by a hardware security module's own provider, or by an older CryptoAPI provider, writes no 5058.

To find the key container of a certificate, look at the certificates in the store: Microsoft's event page shows certutil -store -user my output for user certificates, where the Key Container line gives the name that appears in KeyName. For a CA, the CA certificate is in the computer's personal store.

Fields

In Event Viewer order. The field names are those of the event XML, from the event template that ships with Windows.

FieldWhat it holdsSince
Security IDSubjectUserSidSubjectSID of the account that requested the key file operation. Event Viewer resolves it to an account name when it can.v0
Account NameSubjectUserNameSubjectName of that account. For Local System it is the computer account, a name that ends with $.v0
Account DomainSubjectDomainNameSubjectDomain of the account, usually as a NetBIOS name, the computer name for a local account, or NT AUTHORITY for well-known principals.v0
Logon IDSubjectLogonIdSubjectHexadecimal ID of the account's logon session. It matches the Logon ID of the 4624 event and of a 5059 event of the same session on the same computer.v0
Process IDClientProcessIdProcess InformationID of the process behind the operation, in decimal (shown as Process ID). Not documented by Microsoft. Version 1.v1
Process Creation TimeClientCreationTimeProcess InformationStart time of that process (shown as Process Creation Time). With the process ID it identifies one run of the process. Not documented by Microsoft. Version 1.v1
Provider NameProviderNameCryptographic ParametersKey storage provider that performed the operation. Microsoft lists Microsoft Software Key Storage Provider and Microsoft Smart Card Key Storage Provider.v0
Algorithm NameAlgorithmNameCryptographic ParametersAlgorithm of the key, for example RSA, DSA, DH, or an ECDH or ECDSA curve such as ECDSA_P256 or ECDH_P521. UNKNOWN for the Read persisted key from file operation, as Microsoft notes.v0
Key NameKeyNameCryptographic ParametersName of the key container the operation used. Compare it with the Key Container that certutil shows for a certificate, such as the CA certificate, to know which key was involved.v0
Key TypeKeyTypeCryptographic ParametersWhether the key belongs to a user or to the computer, as a message code. %%2500 user key, %%2499 machine key.v0
File PathKeyFilePathKey File Operation InformationFull path and name of the key file. Microsoft's CNG documentation places user keys under the user's AppData folder (Microsoft\Crypto\Keys) and shared machine keys under the all-users profile (Microsoft\Crypto\Keys), with Local System keys in Microsoft\Crypto\SystemKeys.v0
OperationKey File Operation InformationOperation performed on the file, as a message code. %%2456 Open key file, %%2457 Delete key file, %%2458 Read persisted key from file, %%2459 Write persisted key to file.v0
Return CodeReturnCodeKey File Operation InformationResult in hexadecimal. 0x0 on success, otherwise the error code of the failure.v0

Event versions

The template has two versions. Version 0 is the one Microsoft's event page documents. Version 1 adds ClientProcessId and ClientCreationTime, the process behind the operation and its start time, shown in Event Viewer as Process ID and Process Creation Time. Microsoft does not document version 1.

  • Version 0: 11 fields
  • Version 1: 13 fields, adds ClientProcessId, ClientCreationTime

Values to know

Operation

ValueMeaningSignal
%%2458Read persisted key from fileThe key was loaded from its file. Algorithm Name is UNKNOWN for this operation, as Microsoft notes. On a CA server, for the CA's key container and a named account, read it with the 5059 events of the same session.Worth knowing
%%2459Write persisted key to fileA key file was written, for example a new or renewed certificate's key.Worth knowing
%%2457Delete key fileMicrosoft gives deletion as an example of an operation worth its own monitoring rule.Worth knowing
%%2456Open key fileThe text comes from msobjs.dll; Microsoft's event page does not list this operation.Worth knowing

Security ID SubjectUserSid

ValueMeaningSignal
S-1-5-18, S-1-5-19 or S-1-5-20Local System, Local Service or Network ServiceServices opening their own keys.Noise
Any other SIDA named accountOn a CA server, compare KeyName with the CA's key container.Worth knowing

Key Type KeyType

ValueMeaningSignal
%%2499Machine keyA key stored for the computer rather than for a user.Worth knowing
%%2500User keyA key stored in a user's profile.Worth knowing

Return Code ReturnCode

ValueMeaningSignal
0x0SuccessExpected
Any other valueThe operation failedWritten as an Audit Failure event with the error code.Failure

Volume and noise

Microsoft rates Audit Other System Events Low; most of the subcategory is the start and stop events of the Windows Firewall service and driver. The volume of 5058 follows how often software opens keys held by the two providers: services that use certificates with keys in the Microsoft Software Key Storage Provider can write it routinely, usually as Local System, Local Service or Network Service, and Microsoft names certificate renewal as one source.

Keeping it manageable

  • No rule of the library reads 5058. On certification authority servers, keep every event whose KeyName is the CA's key container, whatever the account: the library's CA private key export page lists a read of the key file by the same account among the events to read around a 5059 export.
  • Elsewhere, Local System, Local Service and Network Service (S-1-5-18, S-1-5-19, S-1-5-20) opening machine keys are most of the volume and can be left out where volume is the limit.
  • Microsoft suggests building monitoring on specific key names or operations, such as Delete key file (%%2457), rather than collecting every event.
  • Join it to 5059 and to 4624 through SubjectLogonId on the same computer to see which session read a key file and then exported the key.

Sample event

Version 1, with made-up values.

<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="Microsoft-Windows-Security-Auditing" Guid="{54849625-5478-4994-a5ba-3e3b0328c30d}" />
    <EventID>5058</EventID>
    <Version>1</Version>
    <Level>0</Level>
    <Task>12292</Task>
    <Opcode>0</Opcode>
    <Keywords>0x8020000000000000</Keywords>
    <TimeCreated SystemTime="2026-11-18T09:30:12.4567890Z" />
    <EventRecordID>1048576</EventRecordID>
    <Correlation />
    <Execution ProcessID="712" ThreadID="2408" />
    <Channel>Security</Channel>
    <Computer>CA01.corp.example.com</Computer>
    <Security />
  </System>
  <EventData>
    <Data Name="SubjectUserSid">S-1-5-21-1004336348-1177238915-682003330-1104</Data>
    <Data Name="SubjectUserName">alice</Data>
    <Data Name="SubjectDomainName">CORP</Data>
    <Data Name="SubjectLogonId">0x5d3a41</Data>
    <Data Name="ClientProcessId">6204</Data>
    <Data Name="ClientCreationTime">2026-11-18T09:29:58.1234567Z</Data>
    <Data Name="ProviderName">Microsoft Software Key Storage Provider</Data>
    <Data Name="AlgorithmName">UNKNOWN</Data>
    <Data Name="KeyName">CORP-ISSUING-CA</Data>
    <Data Name="KeyType">%%2499</Data>
    <Data Name="KeyFilePath">C:\ProgramData\Microsoft\Crypto\Keys\6d1f8a0c3b7e4a52c9e0f1a2b3c4d5e6_4b2a9c1e-7d3f-4e8a-b5c6-0f1e2d3c4b5a</Data>
    <Data Name="Operation">%%2458</Data>
    <Data Name="ReturnCode">0x0</Data>
  </EventData>
</Event>

Attacks this event reveals

No detection rule or detection logic in our library reads this event yet. It is documented here because it sits next to the events they read: it explains them, follows from them or is the trace a defender looks for around them (see Related events).

Frequently asked questions

What is the difference between events 5058 and 5059?

5058 records an operation on a key file (open, read, write, delete). 5059 records the export or import of a key through the provider, and Microsoft notes that its export operation is also written when a key is only read for use. Read them together, by key name and logon session; the library's CA private key export page lists a key file read by the same account among the events around a 5059 export.

Why does event 5058 show UNKNOWN as the algorithm?

Microsoft notes that Algorithm Name is UNKNOWN for the Read persisted key from file operation. Identify the key by its name (the key container) and its file path instead.

Why do I see no 5058 for a key I know is used?

Either Audit Other System Events is off on that computer, or the key is not held by the Microsoft Software or Smart Card Key Storage Provider. Keys in a hardware security module's provider or in an older CryptoAPI provider write no 5058.

References