Corrupted data while trying to decrypt from swift

28 views
Skip to first unread message

Flow

unread,
Aug 22, 2017, 6:41:50 PM8/22/17
to rncryptor
Hey guys, 
Here is what I'm trying to achieve:
- Encrypt data "testkey" with password: "test password" from ruby implementation
- get hmac key and cipher key along with actual encrypted data
- base64 encode these 3 elements and use them in my iOS app
- in the app using RNCCryptor swift implementation (release version 5.0.1): 
 - Initialize RNCCryptor with base64decoded keys
 - Perform decryption
 - here is a code snippet :
 



   
func decrypt(data: Data, 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" and prints nil using .utf8 encoding

 

       } 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!)



 Any pointers to what may lead to this issue ?

Thanks !
Reply all
Reply to author
Forward
0 new messages