PSPDFAESCryptoInputStream

Objective-C


@interface PSPDFAESCryptoInputStream : PSPDFCryptoInputStream

Swift

class AESCryptoInputStream : CryptoInputStream

AES encryption, RNCryptor data format (see https://github.com/RNCryptor/RNCryptor-Spec/blob/master/RNCryptor-Spec-v3.md )

  • Designated initializer with the passphrase. The encryption key salt and HMAC key salt will be loaded from the file header.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithInputStream:(nonnull NSInputStream *)stream
                                     passphrase:(nonnull NSString *)passphrase;

    Swift

    init(inputStream stream: InputStream, passphrase: String)
  • On the first call the provided data buffer size must be at least 98 bytes (82 bytes if original data were < 16 bytes) due to the RNCryptor data format, otherwise an exception will be thrown.

    Declaration

    Objective-C

    - (NSInteger)read:(nonnull uint8_t *)buffer maxLength:(NSUInteger)len;

    Swift

    func read(_ buffer: UnsafeMutablePointer<UInt8>, maxLength len: UInt) -> Int
  • Use this method to close the stream and append the provided data to previously decrypted data.

    Declaration

    Objective-C

    - (nullable NSData *)closeWithData;

    Swift

    func closeWithData() -> Data?

    Return Value

    leftovers of the decrypted data (due to the way CBC decryption works). Returns nil is the error is occurred, otherwise return NSData instance (even if there is no decrypted data left).

  • DO NOT CALL this method to close the stream. Instead, call the - (NSData *)closeWithData; Throws the exception if called.

    Declaration

    Objective-C

    - (void)close;

    Swift

    func close()