<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.2.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreGraphics",
  "identifier" : "/documentation/CoreGraphics/CGPDFDocument/unlockWithPassword(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Graphics",
      "CoreGraphics"
    ],
    "preciseIdentifier" : "c:@F@CGPDFDocumentUnlockWithPassword"
  },
  "title" : "unlockWithPassword(_:)"
}
-->

# unlockWithPassword(_:)

Unlocks an encrypted PDF document when a valid password is supplied.

```
func unlockWithPassword(_ password: UnsafePointer<CChar>) -> Bool
```

## Parameters

`password`

A pointer to a string that contains the password.

## Return Value

A Boolean that, if <doc://com.apple.documentation/documentation/Swift/true>, indicates that the document has been successfully unlocked. If the value is <doc://com.apple.documentation/documentation/Swift/false>, the document has not been unlocked.

## Discussion

Given an encrypted PDF document and a password, this function does the following:

- Sets the lock state of the document, based on the validity of the password.
- Returns <doc://com.apple.documentation/documentation/Swift/true> if the document is unlocked.
- Returns <doc://com.apple.documentation/documentation/Swift/false> if the document cannot be unlocked with the specified password.

Unlocking a PDF document makes it possible to decrypt the document and perform other privileged operations. Different passwords enable different operations.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)