I'm trying to decrypt a message sent from our server.
Both our server and my Android client side uses the encryption code from here:
https://gist.github.com/jafetsanchez/1080133
- The server uses the CS code to encrypt the message
- My android client uses the java code to decrypt the message
I want to add the decryption feature to my iPhone client app with Swift. However I'm not sure how to do it with iOS tools.
I'm using CryptoSwift
Here's what I tried to do:
let iVector: [UInt8] = [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
]
let encryptedMessage = "encrypted_message_encrypted_message_encrypted_message_encrypted_message_"
let password = "passwordpassword"
do {
let aes = try AES(key: password, iv: String(bytes: iVector, encoding: .utf8)!, padding: .pkcs7) // aes128
let decryptedText = try aes.decrypt(encryptedMessage.bytes)
let data = Data(bytes: decryptedText, count: decryptedText.count)
if let string = String(data: data, encoding: .utf8) {
print(string)
} else {
print("not a valid UTF-8 sequence")
}
} catch { }
Right now i'm getting error: CryptoSwift.AES.Error.dataPaddingRequired
In addition, I'm not sure how to combine the MD5 hashing there.