HiI am currently using chilkat ( refer : https://www.chilkatsoft.com/downloads_ios.asp) for json web encryption and wrapping a cek (content encryption )key to the JWE object. This is currently supported by chilkat using a method setWrappingKey. For example I use it as below let jweProtHdr = CkoJsonObject()
jweProtHdr!.load(headerJson)
jwe!.setProtectedHeader(jweProtHdr)
print("JWE Protected Header: \(jweProtHdr!.emit())")
jwe!.setWrappingKey(0, encodedKey: cekKey, encoding: "base64")
Question : is Chilkat approved by apple to use used for production purposes ?.Or is there any other alternatives or similar libraries available which are free to be used.Does apple have its own APIs to support JWE json web encrytion ?ThanksDeepesh
Post
Replies
Boosts
Views
Activity
Hi AllI am trying to convert json jwk pulbic ec key to data format and i written below code which does that. But the data returned is 65 bytes in keyData variable below, instead of 32 bytes. Currently I am trying to pass this data of 32 bytes to GMEllipticCurveCrypto ( GMEllipticCurveSecp256r1 ) library which helps me create a shared secret but only takes in 32 bytes and if I pass this 65 bytes of data then I see a crash with error message as : Terminating app due to uncaught exception 'Invalid Key' ( reference : https://stackoverflow.com/questions/62063112/ios-creating-shared-secret-from-gmellipticcurvecrypto-using-a-public-jwk-ec-ke)So can anyone please possibly help me generate a 32 bytes of data from public EC x and y values of public JWK key ? var xStr = "XUvZlQ3ZYmB2kg-9fySt6Nk30ZnXAPWFa5tnIUGZuxs"
var yStr = "sHHTw0MHoiWw0lj7eOjgy95la1LOiMFpDqdolTZ1Trw"
//Padding required
xStr = xStr.replacingOccurrences(of: "-", with: "+").replacingOccurrences(of: "_", with: "/")
if xStr.count % 4 == 2 {
xStr.append("==")
}
if xStr.count % 4 == 3 {
xStr.append("=")
}
yStr = yStr.replacingOccurrences(of: "-", with: "+").replacingOccurrences(of: "_", with: "/")
if yStr.count % 4 == 2 {
yStr.append("==")
}
if yStr.count % 4 == 3 {
yStr.append("=")
}
let xBytes = Data(base64Encoded: xStr)
let yBytes = Data(base64Encoded: yStr)
//Now this bytes we have to append such that [0x04 , /* xBytes */, /* yBytes */, /* dBytes */]
//Initial byte for uncompressed y as Key.
let keyData = NSMutableData.init(bytes: [0x04], length: [0x04].count)
keyData.append(xBytes!)
keyData.append(yBytes!)
//keyData.append(dBytes)
let attributes: [String: Any] = [
kSecAttrKeyType as String: kSecAttrKeyTypeEC,
kSecAttrKeyClass as String: kSecAttrKeyClassPrivate,
kSecAttrKeySizeInBits as String: 256,
kSecAttrIsPermanent as String: false
]
var error: Unmanaged?
let keyReference = SecKeyCreateWithData(keyData as CFData, attributes as CFDictionary, &error)
print(keyData)
Hi AllI am generating a sharedSecret using apples API. When i use the same shared key inside my JWE object and send it to server, the server throws a pad block corrupted error / exception. I am pretty sure that the error is happening due to the way i have created the shared key. This is because when i flip that implementation of shareSecret using a 3rd party library it works fine. I am trying to get rid of this 3rd party implementation and trying to write my own implemenation. Can anyone suggest / spot any issues with my sharedSecret function below. If not can anyone let me know how to generate a shared secret ( 32 bytes ) out of a private and public EC key ?Below Implementation which generates pad block corrupted exception. let sharedZ = try! ecdhDeriveBits(ecPrivJwk: keyPair.getPrivate(),
ecPubJwk: publicKey,
bitLen: 256)
func ecdhDeriveBits(ecPrivJwk: ECPrivateKey, ecPubJwk: ECPublicKey, bitLen: Int = 0) throws -> Data {
if ecPrivJwk.crv != ecPubJwk.crv {
throw NSError(domain: "key derive fail", code: 10, userInfo: nil)
}
let pubKey = try ecPubJwk.converted(to: SecKey.self)
let eprivKey = try ecPrivJwk.converted(to: SecKey.self)
let parameters = [String: Any]()
var error: Unmanaged?
guard let derivedData = SecKeyCopyKeyExchangeResult(
eprivKey,
SecKeyAlgorithm.ecdhKeyExchangeStandard,
pubKey,
parameters as CFDictionary,
&error)
else {
let errStr = error?.takeRetainedValue().localizedDescription ?? "Derive Key Fail"
throw NSError(domain: "key derive fail", code: 10, userInfo: nil)
}
return bitLen > 0 ? truncateBitLen(from: (derivedData as Data), bitLen: bitLen) : (derivedData as Data) as Data
}Implemention of sharedSecret which works fine using a 3rd party library called chilkat.let sdkPrivateKey: CkoPrivateKey = loadPrivateKey(privateKeyPkcs1Enc: sdkPrivateKey)!
let sharedKey: Data = getSharedSecretKey(clientPrivateKey: sdkPrivateKey, serverPublicKey: acsPublicKey1)!
func loadPrivateKey(privateKeyPkcs1Enc: String) -> CkoPrivateKey? {
let success: Bool
let privateKey = CkoPrivateKey()
success = privateKey!.loadPkcs1(Data(base64Encoded: privateKeyPkcs1Enc))
if success != true {
print("\(privateKey!.lastErrorText ?? "no key")")
return nil
}
return privateKey
}
func getSharedSecretKey(clientPrivateKey: CkoPrivateKey, serverPublicKey: CkoPublicKey) -> Data? {
JweHelper.unlockLibrary()
let eccClient = CkoEcc()
let sharedSecret: String? = eccClient!.sharedSecretENC(clientPrivateKey, pubKey: serverPublicKey, encoding: "base64")
return Data(base64Encoded: sharedSecret!)
}
Hi TeamI am trying to perform a EC point ( x, y ) multuplication with private EC key ( d ). I dont see much support or APIs in swift. However i did see some discussion happening on the swift community over this way back in 2019. Has anything change since then and do we have support to perform this stand EC point mulitplication operation in swift ?refer : https://forums.swift.org/t/cryptography-for-the-swift-ecosystem/24728/21refer : https://www.programcreek.com/java-api-examples/?class=org.bouncycastle.math.ec.ECPoint&method=multiplyThanksDeepesh
Hi All,I am creating a standard custom swift framework with universal binary script to support both iOS Sim and Device. But when i drag the generated .framework file to my test app and try to run it on simulator I see a crash with below logs.dyld: Library not loaded: @rpath/GMEllipticCurveCrypto.framework/GMEllipticCurveCrypto Referenced from: /Users/deepesh.vasthimal/Library/Developer/CoreSimulator/Devices/1B740BA0-6105-4F5D-9C3A-E07509D485F6/data/Containers/Bundle/Application/CAF4473D-3AE5-4A3E-9341-5ACEE4C089E1/MyRetailOut.app/Frameworks/Payment.framework/Payment Reason: image not foundI have seen tons of similar issues and I have tried almost every solution but I cant seem to fix this issue. Can you please let me know what is required while creating custom swift frameworks which internally is using a few third part pods. Also I dont want to expose these 3rd part pods to my test app. Also this was easily support with Objc has anything changed with swift ? ThanksDeepesh
Hi Teami am trying to perform a ECC point multiply operation from public EC JWK key x and y values with private EC key d value. This is currently supported in Android with a thirday part library called bouncy castle. Can anyone guide or help how to proceed with this in iOS. I have read the docs and I could not find any support for ECC point multiply operation in iOS. ThanksDeepesh
I am trying to build a Swift framework containing cocoapods, using the below universal framework script got from here: Swift universal framework depending on pod
The build fails when using Xcode 12 and UseModernBuildSystem=NO:
The Legacy Build System will be removed in a future release. You can configure the selected build system and this deprecation message in File > Workspace Settings.
Command PhaseScriptExecution failed with a nonzero exit code
error when using Xcode 12 and modern build system:
error: accessing build database
"/Users/user/Library/Developer/Xcode/DerivedData/SnapKit-gldcozqrglacwhcqsctatmsoiouc/Build/Intermediates.noindex/XCBuildData/build.db": disk I/O error
Does anyone know the right solution for this problem or a workaround?
Hi All,
After a lot of read on various blogs and stackoverflow i have realised that apple has no proper solution for creating swift frameworks which contains 3rd party dependencies. Can you please guide me through the proper solution in this case and what is the proper script to be used as well to create a framework which can be distributed both for simulator and devices provided my framework contains 3rd party cocoapods.
Any documentation example projects will help.
Thanks
Hi All
I am using a custom framework created using 3 different cocoapods. I am using this custom framework in a client app by dropping the xc framework created. As soon as the client app launches it crashes with below crash logs. I have seen this issue reported many other places on apple and stackoverflow but i could not find a proper answer which worked for me. Now i have uploaded both the client app and the framework repo to github so that anyone trying to help me can actually see the set up and code. Please can any one suggest a proper solution to this issue.
Framework : https://github.com/deepesh259nitk/PaymentsKit
Client App : https://github.com/deepesh259nitk/PaymentClient
Crash Logs on app launch
dyld: Symbol not found: _$s11CryptoSwift7PaddingO5pkcs7yA2CmFWC
Referenced from: /Users/deepesh.vasthimal/Library/Developer/Xcode/DerivedData/PaymentClient-bnsircrdeaciebedmqaliyxezdqe/Build/Products/Debug-iphonesimulator/PaymentsKit.framework/PaymentsKit
Expected in: /Users/deepesh.vasthimal/Library/Developer/CoreSimulator/Devices/A0876375-98D5-4215-A139-68F29E787388/data/Containers/Bundle/Application/D954732B-EDDC-478E-85C4-C5C9B14FDDEE/PaymentClient.app/Frameworks/CryptoSwift.framework/CryptoSwift
in /Users/deepesh.vasthimal/Library/Developer/Xcode/DerivedData/PaymentClient-bnsircrdeaciebedmqaliyxezdqe/Build/Products/Debug-iphonesimulator/PaymentsKit.framework/PaymentsKit
dyld: launch, loading dependent libraries
DYLD_SHARED_CACHE_DIR=/Users/deepesh.vasthimal/Library/Developer/CoreSimulator/Caches/dyld/19H2/com.apple.CoreSimulator.SimRuntime.iOS-14-0.18A372
DYLD_ROOT_PATH=/Users/deepesh.vasthimal/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot
DYLD_LIBRARY_PATH=/Users/deepesh.vasthimal/Library/Developer/Xcode/DerivedData/PaymentClient-bnsircrdeaciebedmqaliyxezdqe/Build/Products/Debug-iphonesimulator:/Users/deepesh.vasthimal/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Users/deepesh.vasthimal/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib:/Users/de
Things which I have tried.
I tried removing the CryptoSwift completely to see if the error happens due to this pod, but the crash then comes to JOSESwift which is another pod.
I have realised the crash happens as it cannot find specific symbols both in CryptoSwift and JOSESwift. And also when i use specific methods of these libraries.
for example if i use the AES method of CryptoSwift if you see my repo for framework, by adding the below code the crash happens, Just including the pod does not crash but usage of it produces the crash.
_$s11CryptoSwift7PaddingO5pkcs7yA2CmFWC
guard let aesObject = try? AES(key: [UInt8](Data()),
blockMode: CBC(iv: Array(Data())),
padding: .pkcs7) else {
return ""
}
3. I am also adding the pods in the client app so that it does not get added twice if you see Client App repo you will see all the 3 pods are added.
How as developers we can get access to Proximity Reader APIs ? refer
Proximity Reader