Issue trying to decrypt from swift a data encoded with ruby implementation

49 views
Skip to first unread message

Flow

unread,
Aug 22, 2017, 6:41:56 PM8/22/17
to rncryptor

Hey guys I'm running into an issue trying to decrypt data, here is what I'm trying to achieve:

  1. Encrypt data "testkey" with ruby implementation  (password used "testpassword")
  2. Get the encrypted data along with hmac key and cipher key generated by the algorithm
  3. pass these data as base64 encoded string to my iOS app
  4. in the iOS app transform these strings into swift Data type
  5. Decrypt the encrypted data using keys
Here is a code snippet of the swift code:

    public static func decrypt(data: Data, using, encryptionKey: Data, hmacKey: Data) {      

       let cryptor = RNCryptor.DecryptorV3(encryptionKey: encryptionKey, hmacKey: hmacKey)

       do {

           let originalData = try cryptor.decrypt(data: data)

           print(String(data: originalData, encoding: .ascii)) // Prints ";\u{01}-ñ\u{01}‘t,ìfÂVå–\"»testkey" with .utf8 encoding prints "nil"  


        } catch {

           print(error)

       }

  }


        let data = Data(base64Encoded: "AwB2+JcLqdFBstqdsZgX+jce97B0api4Km1rl+8hpePv4okgVGtmhBSBkKb8w/oxG66aHszBiSlZuxgu2OAjA8jU8UoHmalhvZAHbT80CFcZIw==")


        let key = Data(base64Encoded: "VDBaN4voLTO4bs4VnX5zIDWRNtmk1mQ5UPQJNA9IMLQ=")


        let hmac = Data(base64Encoded: "LhLHKyN654JgKTxKJriovZxN3tzHjjpAZsnBX1UhhzQ=")


        decrypt(data: data!, encryptionKey: key!, hmacKey: hmac!)


the printed chain ";\u{01}-ñ\u{01}‘t,ìfÂVå–\"»testkey" remain the same every time I run the program or if I encrypt the same data with the same password

Any idea of what I am doing wrong here ?

Regards,
Flow.

Rob Napier

unread,
Dec 8, 2017, 5:47:14 PM12/8/17
to rncryptor
I'm sorry for the long delay on this. If you're still fighting this, I suspect you're just encrypting the wrong thing in the first place; maybe a structure that includes "testkey" in it, but is not actually those bytes. Can you send the ruby code that encrypts this?

-Rob
Reply all
Reply to author
Forward
0 new messages