<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppleArchive",
  "identifier" : "/documentation/AppleArchive/ArchiveByteStream/encryptionStream(writingTo:encryptionContext:flags:threadCount:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Apple Archive",
      "AppleArchive"
    ],
    "preciseIdentifier" : "s:12AppleArchive0B10ByteStreamC010encryptionD09writingTo0E7Context5flags11threadCountACSgAC_AA0b10EncryptionH0CAA0B5FlagsVSitFZ"
  },
  "title" : "encryptionStream(writingTo:encryptionContext:flags:threadCount:)"
}
-->

# encryptionStream(writingTo:encryptionContext:flags:threadCount:)

Creates a encryption sequential input stream.

```
static func encryptionStream(writingTo encryptedStream: ArchiveByteStream, encryptionContext context: ArchiveEncryptionContext, flags: ArchiveFlags = [], threadCount: Int = 0) -> ArchiveByteStream?
```

## Parameters

`encryptedStream`

An input stream that provides encrypted and compressed data. The stream must implement [`read(into:)`](/documentation/AppleArchive/ArchiveByteStreamProtocol/read(into:)) and [`read(into:atOffset:)`](/documentation/AppleArchive/ArchiveByteStreamProtocol/read(into:atOffset:)).

`context`

The encryption context that provides options and credentials.

`flags`

Flags that control the behavior of the operation.

`threadCount`

The number of worker threads that the operation uses, set to `0` for default.

## Return Value

A new archive byte stream.

## Discussion

The operation reads decompressed and decrypted data from the supplied archive byte stream, `encryptedStream`.

Create the encryption context from `encryptedStream`, and add the credentials to unlock the stream before calling this function.

The stream that the function returns only implements [`read(into:)`](/documentation/AppleArchive/ArchiveByteStreamProtocol/read(into:)) and [`read(into:atOffset:)`](/documentation/AppleArchive/ArchiveByteStreamProtocol/read(into:atOffset:)).

---

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)