Search code examples
iosobjective-cencryptionrubymotiondes

DES encryption in Rubymotion


How can I encrypt/decrypt a string with DES algorithm on iOS using Rubymotion?

There are very few examples even on Obj-C, and they are hardly translatable to Rubymotion.


Solution

  • I had to install CommonCrypto pod.

    After I used this code to encrypt with DES:

    string = "string to encrypt"
    data = params.dataUsingEncoding(NSUTF8StringEncoding)
    
    errorPtr = nil # You can use a real error object here if you need
    encrypted_data      = data.DESEncryptedDataUsingKey(User.first.key, error: errorPtr) 
    

    Also you can check other aviable encryption and decryption methods in /vendors/Pods/CommonCrypto/NSData+CommonCrypto.m file.