PSPDFCryptor
Objective-C
@interface PSPDFCryptor : NSObject
Swift
class Cryptor : 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/RNCryptor/RNCryptor-Spec/blob/master/RNCryptor-Spec-v3.md
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 hhttps://github.com/RNCryptor/RNCryptor-Spec/blob/master/RNCryptor-Spec-v3.md
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/RNCryptor/RNCryptor-Spec/blob/master/RNCryptor-Spec-v3.md
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 (nonatomic, nullable) id<PSPDFFileManager> fileManager;
Swift
var fileManager: FileManager? { get set }
-
Use
CryptorError
instead.Declaration
Swift
@available(*, deprecated, message: "`Cryptor.ErrorCode` has been renamed to `CryptorError` in PSPDFKit 9.4 for iOS and 4.4 for macOS.") public typealias ErrorCode = CryptorError