Shell script which uses Swift and CryptoKit underneath doesn't work after updating to Xcode 15 and MacOS Sonoma


I'm having some trouble running a shell script that worked before I updated the Xcode and my MacOS. This is probably connected to the command line tools which were updated with these upgrades. I can't switch to an older version of the command line tools to verify this theory tho...

The script uses CryptoKit to decrypt some data which was encrypted using a SymmetricKey. The script:

# This script decrypts encrypted data using a symmetric key.

# Check for the correct number of arguments
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <encrypted_file_path> <decrypted_file_path>"
exit 1

# Get the input arguments

# Find the path to the script's directory
scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# Check if the symmetric key file exists in the same directory
if [ ! -f "$symmetricKeyPath" ]; then
echo "SymmetricKey file was not found in the same directory as the script."
exit 1

# Decrypt the data
swift - <<EOF
import Foundation
import CryptoKit

let symmetricKeyURL = URL(fileURLWithPath: "$symmetricKeyPath")
let encryptedDataURL = URL(fileURLWithPath: "$encryptedFilePath")
let decryptedDataURL = URL(fileURLWithPath: "$decryptedFilePath")

guard let symmetricKeyData = try? Data(contentsOf: symmetricKeyURL) else {
    fatalError("Failed to read symmetric key data")

guard let encryptedData = try? Data(contentsOf: encryptedDataURL) else {
    fatalError("Failed to read encrypted data")

do {
    // Decrypt the data using AES-GCM
    let decryptionKey = SymmetricKey(data: symmetricKeyData)
    let sealedBox = try AES.GCM.SealedBox(combined: encryptedData)
    let decryptedData = try, using: decryptionKey)

    // Write the decrypted data to a file
    try decryptedData.write(to: decryptedDataURL)

    print("Decryption successful. Decrypted file saved at \(decryptedDataURL)")
} catch {
    print("Decryption failed: \(error.localizedDescription)")


The code in the project which encrypts the data and retrieves the key:

func encryptSymmetric(data: Data, password: String) throws -> (Data, Data) {
        let key = SymmetricKey(size: .bits256)

        guard let cipher = try? AES.GCM.seal(data, using: key).combined else {
            throw SomeCustomError.failedToEncryptData

        let keyData = key.withUnsafeBytes { Data($0) }

        return (cipher, keyData)

The error I'm presented with in the terminal is

JIT session error: Symbols not found: [ _$s9CryptoKit3AESO3GCMO4open_5using10Foundation4DataVAE9SealedBoxV_AA12SymmetricKeyVtKFZ, _$s9CryptoKit12SymmetricKeyVMa, _$s9CryptoKit3AESO3GCMO9SealedBoxV8combinedAGx_tKc10Foundation12DataProtocolRzlufC, _$s9CryptoKit12SymmetricKeyV4dataACx_tc10Foundation15ContiguousBytesRzlufC, _$s9CryptoKit3AESO3GCMO9SealedBoxVMa ]
Failed to materialize symbols: { (main, { _$s4main16encryptedDataURL10Foundation0D0Vvp, _$s4main15symmetricKeyURL10Foundation0D0Vvp, _$s10Foundation4DataVAcA0B8ProtocolAAWL, _$s4main16decryptedDataURL10Foundation0D0Vvp, _$sSa12_endMutationyyF, _$ss5print_9separator10terminatoryypd_S2StFfA0_, _$ss27_finalizeUninitializedArrayySayxGABnlF, _main, _$s10Foundation4DataV15_RepresentationOWOe, _$sSSWOh, _$ss5print_9separator10terminatoryypd_S2StFfA1_, _$s10Foundation4DataV5write2to7optionsyAA3URLV_So20NSDataWritingOptionsVtKFfA0_, ___swift_allocate_value_buffer, __swift_FORCE_LOAD_$_swiftFoundation_$_main, _$s10Foundation4DataV10contentsOf7optionsAcA3URLVh_So20NSDataReadingOptionsVtKcfcfA0_, __swift_FORCE_LOAD_$_swiftXPC_$_main, _$s10Foundation4DataV15_RepresentationOWOy, ___swift_project_value_buffer, _$s10Foundation4DataVAcA0B8ProtocolAAWl, __swift_FORCE_LOAD_$_swiftIOKit_$_main, _$ss26DefaultStringInterpolationVWOh, __swift_FORCE_LOAD_$_swiftCoreFoundation_$_main, _$s10Foundation3URLVACs23CustomStringConvertibleAAWl, __swift_FORCE_LOAD_$_swiftDarwin_$_main, __swift_FORCE_LOAD_$_swiftObjectiveC_$_main, _$s10Foundation3URLVACs23CustomStringConvertibleAAWL, __swift_FORCE_LOAD_$_swiftDispatch_$_main }) }

This leads me to believe that linking might not be working properly. I also found this thread where someone had the same issue but with a different framework.

NOTE: If I try to decrypt the data in my project, it works without any issues even on Xcode 15. It only fails if I try to run this script which worked before when I had the previous version of command line tools. I even tried updating to Xcode 15.1 beta and its command line tools, without success.

Any feedback is appreciated. Thank you.

Same here, any solution for this?

@appletastesgood I issued a report under the number FB13264327. You can do it yourself too, so they get more reported issues and notice the severity of the situation.

Shell script which uses Swift and CryptoKit underneath doesn't work after updating to Xcode 15 and MacOS Sonoma