简体   繁体   中英

Converting Data object to String in swift returning nil

I'm using the following code to convert Data to String in swift. The returned String is nil. Could you please help me identify what is going wrong. Thank you.

let dataObject = try RSAUtils.encryptWithRSAPublicKey(str: textToEncrypt!, pubkeyBase64: pubKeyB64)


let dataToString = String(data: dataObject!, encoding: String.Encoding.utf8) as String!

this base 64 encryptedData by RSAUtils lib so use this

if ( dataObject != nil ) {
    let encryptedDataText = dataObject!.base64EncodedString(options: NSData.Base64EncodingOptions())
    NSLog("Encrypted with pubkey: %@", encryptedDataText)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM