PSPDFCryptor


@interface PSPDFCryptor : NSObject

Simple class that encrypts/decrypts files in a format compatible to PSPDFAESCryptoDataProvider.

  • Generates a key with (kCCPRFHmacAlgSHA1, 10k iterations, used in new file format - https://github.com/RNCryptor/RNCryptor-Spec/blob/master/RNCryptor-Spec-v3.md ) WARNING! In previous versions it generated (kCCPRFHmacAlgSHA256, 50k used in the legacy file format. Use - (NSData *)keyFromPassphrase:(NSString *)passphrase salt:(NSString *)salt PRF:(CCPseudoRandomAlgorithm)prf rounds:(uint)rounds; to generate key to decrypt legacy file format.

    Declaration

    Objective-C

    - (nonnull NSData *)keyFromPassphrase:(nonnull NSString *)passphrase
                                     salt:(nonnull NSString *)salt;

    Swift

    func key(fromPassphrase passphrase: String, salt: String) -> Data
  • Generate a key with legacy file format PRF kCCPRFHmacAlgSHA256 and 50000 number of rounds

    Declaration

    Objective-C

    - (nonnull NSData *)legacyKeyFromPassphrase:(nonnull NSString *)passphrase
                                           salt:(nonnull NSString *)salt;

    Swift

    func legacyKey(fromPassphrase passphrase: String, salt: String) -> Data
  • Encrypt a file (DOES NOT store encryption salt in the file header) Using format https://github.com/rnapier/RNCryptor/wiki/Data-Format

    Declaration

    Objective-C

    - (BOOL)encryptFromURL:(nonnull NSURL *)sourceURL
                     toURL:(nonnull NSURL *)targetURL
                       key:(nonnull NSData *)key
                     error:(NSError *_Nullable *_Nullable)error;

    Swift

    func encrypt(from sourceURL: URL, to targetURL: URL, key: Data) throws
  • Decrypt a file. Both the legacy and the current file formats are supported.

    Declaration

    Objective-C

    - (BOOL)decryptFromURL:(nonnull NSURL *)sourceURL
                     toURL:(nonnull NSURL *)targetURL
                       key:(nonnull NSData *)key
                     error:(NSError *_Nullable *_Nullable)error;

    Swift

    func decrypt(from sourceURL: URL, to targetURL: URL, key: Data) throws
  • Encrypt a file (stores encryption salt in the file header) Using format https://github.com/rnapier/RNCryptor/wiki/Data-Format

    Declaration

    Objective-C

    - (BOOL)encryptFromURL:(nonnull NSURL *)sourceURL
                     toURL:(nonnull NSURL *)targetURL
                passphrase:(nonnull NSString *)passphrase
                     error:(NSError *_Nullable *_Nullable)error;

    Swift

    func encrypt(from sourceURL: URL, to targetURL: URL, passphrase: String) throws
  • Decrypt a file. Both the legacy and the current RNCryptor file formats are supported. For the current file format encryption salt from the file header will be used to construct the encryption key. https://github.com/rnapier/RNCryptor/wiki/Data-Format

    Declaration

    Objective-C

    - (BOOL)decryptFromURL:(nonnull NSURL *)sourceURL
                     toURL:(nonnull NSURL *)targetURL
                passphrase:(nonnull NSString *)passphrase
                     error:(NSError *_Nullable *_Nullable)error;

    Swift

    func decrypt(from sourceURL: URL, to targetURL: URL, passphrase: String) throws
  • Dependency injection property

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic, nullable) id<PSPDFFileManager>
        fileManager;

    Swift

    var fileManager: PSPDFFileManager? { get set }