diff --git a/swift-secure-enclave-tool-v2.swift b/swift-secure-enclave-tool-v2.swift index 238faf7..3f39653 100644 --- a/swift-secure-enclave-tool-v2.swift +++ b/swift-secure-enclave-tool-v2.swift @@ -244,7 +244,7 @@ struct ComputeSecureEnclaveP256EcsignResponse: Codable { struct ComputeSecureEnclaveP256EcdhResponse: Codable { var success: Bool - var shared_secret: String + var shared_secret_hex: String } struct ExternalSpecResponse: Codable { @@ -437,9 +437,18 @@ func computeSecureEnclaveP256Ecdh(request: ComputeP256EcdhRequest) -> ComputeSec let sharedSecret = try p.sharedSecretFromKeyAgreement( with: ephemeralPublicKey) + var shared_secret_hex: String + if sharedSecret.description.starts(with: "SharedSecret: ") { + let str = sharedSecret.description + let startIndex = str.index(str.startIndex, offsetBy: "SharedSecret: ".count) + shared_secret_hex = String(str[startIndex...]) + } else { + shared_secret_hex = sharedSecret.description + } + return ComputeSecureEnclaveP256EcdhResponse( success: true, - shared_secret: sharedSecret.description + shared_secret_hex: shared_secret_hex ) } catch { exitError("\(error)")