Closed Abhijitg11 closed 6 years ago
The exception is raised by the invalid private key string. "keyString" appears to be an invalid string. You can try to set an valid base64String parameter to RSAKey.init method to see if the privateKey is generated properly.
let longstring = "test123" let data = (longstring).data(using: String.Encoding.utf8) let base64 = data!.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue: 0)) let privateKeyC = try! RSAKey.init(base64String: base64, keyType: .PRIVATE)
Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: SwiftyCrypto.SwiftyCryptoError.asn1ParsingFailed
"test123" appears to be an invalid private key string. Try to use a valid string. You can use an online RSA Key generator to test the function.
yes thanks . It works fine i was passing a wrong key string
let publicKeyAttr: [NSObject: NSObject] = [ kSecAttrIsPermanent:true as NSObject, kSecAttrApplicationTag:"com.xeoscript.app.RsaFromScrach.public".data(using: String.Encoding.utf8)! as NSObject, kSecClass: kSecClassKey, // added this value kSecReturnData: kCFBooleanTrue] // added this value let privateKeyAttr: [NSObject: NSObject] = [ kSecAttrIsPermanent:true as NSObject, kSecAttrApplicationTag:"comxeoscriptappRsaFromScrachprivate".data(using: String.Encoding.utf8)! as NSObject, kSecClass: kSecClassKey, // added this value kSecReturnData: kCFBooleanTrue] // added this value
let privateKey = try! RSAKey.init(base64String: (privateKey.base64EncodedString()), keyType: .PRIVATE) Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: SwiftyCrypto.SwiftyCryptoError.keyCreateFailed(Optional(Error Domain=NSOSStatusErrorDomain Code=-50 "Unsupported key type: (null)" UserInfo={NSDescription=Unsupported key type: (null)}))
let privateKey = try! RSAKey.init(base64String: "keyString", keyType: .PRIVATE) Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: SwiftyCrypto.SwiftyCryptoError.invalidBase64String