Working with PST Password Protection Properties

Check for Password protection

The MapiPropertyTag.PR_PST_PASSWORD value from the MapiPropertyTag class is used to check if a file is password protected.

The CRC-32 hash of the password string is stored in the PidTagPstPassword (tag = 0x67ff0003) property in the MessageStore. If this property exists and is non-zero, then the PST is password protected.

The following code snippet shows how to check if a PST file is password protected and whether the given string is a valid password for that PST.

The code snippet below shows two functions, the first check if the PST is password-protected, and the second shows how to check whether a provided password is correct or not.

Remove/Reset the PR_PST_PASSWORD Property

Removal of the PR_PST_PASSWORD property cannot be achieved as other properties are removed from a message store. Instead, we need to set its value to zero (0) in order to get it removed. The “Store” property of the PST class allows access to the store properties of PST instead of MessageStoreProperties of PST in this case.

Set/Change PST Password

The following code snippet shows you how to set a password on PST files.

Password Verification for Password Protected PST Files

Aspose.Email enables the developers to check if the PST file is password protected and to check if the given password is correct or not. For this, the API provides the PersonalStorage.Store.IsPasswordProtected property and PersonalStorage.Store.IsPasswordValid() method. The PersonalStorage.Store.IsPasswordProtected property returns true if the PST file is password protected and false if it is not. The PersonalStorage.Store.IsPasswordValid() method which takes the string password as a parameter and returns true if the password is correct and false it is incorrect.

The following code snippet demonstrates the use of PersonalStorage.Store.IsPasswordProtected property and PersonalStorage.Store.IsPasswordValid() method.

Sample Code

Console Output

The storage is password protected - True Password is valid - True