Windows 11 provides native file-level security via the Encrypting File System (EFS), an integral capability of the NTFS filesystem architecture. While BitLocker encrypts entire disk volumes to prevent offline attacks, EFS allows individual users to encrypt specific files, folders, and working directories independently using public-key cryptography. Although graphical user interface toggles exist in File Explorer properties, the native command-line utility cipher.exe provides systems administrators with granular operational control over encryption states, certificate provisioning, key archiving, and the secure sanitisation of deallocated disk clusters.
Understanding the cipher Command Syntax and Core Parameters
The cipher utility operates directly against directory paths, individual file objects, and storage volume letters. The table below delineates the primary command-line switches and their operational functions:
| Parameter Switch | Operational Function | Administrative Purpose | Execution Scope |
|---|---|---|---|
/e |
Encrypts specified directories or files. | Flags folders so newly created files inherit encryption automatically. | Target directories and child objects. |
/d |
Decrypts specified directories or files. | Removes EFS protection, converting items back to standard plaintext NTFS streams. | Target directories and child objects. |
/s:directory |
Applies operations recursively. | Processes all subfolders and underlying child files across directory trees. | Subtree hierarchy. |
/a |
Applies operation to individual files. | Forces cipher to evaluate individual file targets alongside directory containers. | Specific file objects. |
/w:directory |
Wipes deallocated cluster space. | Overwrites residual traces of deleted files across unused volume sectors. | Volume free space. |
/k |
Generates a new EFS file encryption key. | Creates a new self-signed certificate and associated user private key. | Current user certificate store. |
/r:filename |
Generates recovery agent certificates. | Creates a recovery key pair (.cer and .pfx) for emergency administrative data recovery. |
Designated output directory. |
/c |
Displays detailed encryption metadata. | Outputs certificate thumbprints, encryption users, and recovery agents. | Specified file or folder. |
Querying and Inspecting Encryption Status
Executing cipher without arguments displays the encryption status of the current working directory and every file contained within it. In the terminal output, an E prefix designates an encrypted object, whilst an U designates an unencrypted object.
cipher C:\Accounting\Ledgers
To inspect the cryptographic identity, thumbprint, and recovery certificates bound to a specific confidential file, use the /c switch:
cipher /c "C:\Accounting\Ledgers\Q3_Financials.xlsx"
This command outputs the current user certificate hash, the Data Decryption Field (DDF) header information, and any configured Data Recovery Field (DRF) accounts authorised across the domain.
Encrypting and Decrypting Files and Directories
When implementing EFS, best administrative practice dictates encrypting parent directories rather than individual files alone. This ensures that temporary autosave files, lockfiles, and newly created documents inherit encryption automatically upon generation.
1. Encrypting a Complete Directory Tree
To encrypt a directory and all nested subdirectories and files recursively, combine the /e, /s, and /a switches:
cipher /e /s:"C:\ConfidentialProjects" /a
If an individual file encounters an access lock during execution, cipher logs the failure and continues processing remaining objects without aborting the entire queue.
2. Decrypting Files and Folders
To revert an encrypted folder and its child elements back to standard plaintext storage:
cipher /d /s:"C:\ConfidentialProjects" /a
Backing Up and Archiving EFS Encryption Keys
Because EFS encryption binds data directly to the user account’s cryptographic certificate and private key, resetting a Windows user password or reinstalling the operating system permanently destroys access to encrypted data unless private keys have been exported.
1. Creating an EFS Recovery Agent Certificate
Domain and local administrators can generate a dedicated Data Recovery Agent (DRA) certificate pair using the /r switch:
cipher /r:C:\SecurityKeys\CompanyEFSRecoveryKey
The command prompts for a strong export password to protect the private key. It generates two files:
CompanyEFSRecoveryKey.cer: The public key certificate installed on workstations or distributed via Group Policy.CompanyEFSRecoveryKey.pfx: The password-protected PKCS #12 archive containing the private recovery key, which must be stored in a hardware vault or encrypted offline medium.
2. Renewing and Refreshing Keys
To force the creation of a new personal EFS certificate within the Windows Certificate Store:
cipher /k
To update previously encrypted files across a drive with newly renewed encryption keys without manual decryption and re-encryption:
cipher /u /n
Securely Wiping Residual Free Space with cipher /w
When a file is deleted in Windows 11, the operating system removes its pointer from the NTFS Master File Table (MFT) and marks its clusters as deallocated, but the underlying binary data remains physically intact on the storage platter or NAND flash until overwritten. The /w switch sanitises deallocated storage sectors without modifying or damaging existing live files.
1. How the Sanitisation Algorithm Works
The free space wiping routine executes a three-pass overwrite sequence adhering to robust data sanitisation principles:
- Pass 1 (Zero Fill): Overwrites all unused sectors across the volume with
0x00bytes. - Pass 2 (One Fill): Overwrites all unused sectors across the volume with
0xFFbytes. - Pass 3 (Random Noise): Fills all unused sectors with pseudorandom binary digits.
2. Executing the Free Space Wipe
To sanitise all deallocated sectors across drive D:, specify a directory path located on the target volume:
cipher /w:D:\
Important considerations when executing cipher /w:
- Execution Duration: Depending on volume capacity and drive write speeds, wiping large mechanical hard drives or high-capacity NVMe SSDs may require several hours.
- Application State: Close running applications, background downloads, and virtual machines prior to execution to minimise transient file creation that could allocate sectors mid-operation.
- Solid State Drive (SSD) Considerations: Whilst
cipher /wis effective on traditional rotational disks, modern SSDs utilize wear-levelling algorithms and TRIM instructions. In high-security SSD decommissioning scenarios, hardware-level Secure Erase or BitLocker cryptographic erasure provides supplementary protection.
Troubleshooting Common cipher Execution Errors
When automating or executing cipher operations, administrators frequently encounter specific environmental restrictions:
- Error: “The file cannot be encrypted because the volume does not support it”: EFS requires an NTFS formatted volume. Volumes formatted with FAT32, exFAT, or ReFS do not support EFS metadata structures.
- Error: “Access is Denied”: Ensure the Command Prompt or PowerShell terminal is launched with elevated administrative privileges (Run as Administrator), particularly when executing operations against system directories or multi-user file shares.
- ReadOnly File Attributes: Files marked with the NTFS ReadOnly attribute must have their attribute stripped via
attrib -r "filepath"prior to altering their EFS encryption status.