Crash : AES128 encryption in iOS 10 using Swift 2.1 -
i’m using aes128 encryption. below code i’ve used :
. . . let encjson : string = response.objectforkey("data") as! string let encryptionkey : string = “some key here” //crash on line response = encryptionandconversion.sharedinstance.converencdatatostringwithaes128(encjson, key: encryptionkey) print("response : \(response)") . . . func converencdatatostringwithaes128(message:string, key mykey:string) -> nsdictionary { let data = nsdata(base64encodedstring: message, options: nsdatabase64decodingoptions(rawvalue: 0)) //the value of result comes nil let result = nsstring(data: (data?.aes128decrypteddatawithkey(mykey))!, encoding: nsutf8stringencoding) return convertstringtodictionary(result!) }
what might reason? i’m getting crash on converencdatatostringwithaes128(..)
function reason fatal error: unexpectedly found nil while unwrapping optional value
i’ve cross-verified there no issue message , key.
any appreciated!
not answer, crashes?
let encjson : string = response.objectforkey("data") as! string
to:
guard let encjson = response.objectforkey("data") as? string { print("data not string") return }
Comments
Post a Comment