How to encrypt and decrypt data in Swift 3 form native without using any external lib

Asked

Viewed 105 times

1

I have a service in which must be accessed with a url encrypted.

Is there any way to encrypt data on Swift natively without using these lib cocoapods?

My project doesn’t use any of this and would like to keep it that way if possible.

  • What is the encryption algorithm you are using? Is it an HMAC? Is it an AES? Is it a DES? (specify what the implementation is)

  • Bruno thanks for your return, so this webapi c# uses MD5 but if there is nothing native of Swift that does encryption in MD5 I can change the method of the webapi, I just didn’t want to use any "lib" in my Swift project

  • http://stackoverflow.com/a/32166735/2582714

  • Leonardo Cesar Teixeira thank you, but there is no way to do this natively without having to use these external libraries?????

  • @Juliofigueiredo In the post I sent you, no third party library is being used, but native iOS features. https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/CC_MD5.3cc.html

  • Leonardo Cesar Teixeira, cool I got, honestly did not know that could be made this "bridge" between languages, all the people who told me about it told me to use some external library. Thank you very much

Show 1 more comment

1 answer

0


It helps you?

let senhaMD5 = self.MD5(string: textField.text!)
let stringMD5 = senhaMD5.map { String(format: "%02hhx", $0) }.joined()



func MD5(string: String) -> Data {
    let messageData = string.data(using:.utf8)!
    var digestData = Data(count: Int(CC_MD5_DIGEST_LENGTH))
    _ = digestData.withUnsafeMutableBytes {digestBytes in
        messageData.withUnsafeBytes {messageBytes in
            CC_MD5(messageBytes, CC_LONG(messageData.count), digestBytes)
        }
    }
    return digestData }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.