how decryption AES 256 CBC with 32 bit IV in swift

hi.

i'm making my personal app on xcode with swift language and for use back end data need to decryption because we encrypted data by AES 256 CBC.

I try several method and pods for decryption but no one can't decrypt data that encrypted by 32 bit IV.

its one of my encrypted data:

IV = "Oep6wu+G3qwNAlRWNI+vsg=="


Value = "hqWeO5q9bisLhwObdlWM7nAD3nZW2SpGRoD7W1TXPI+ooOvprCw3E+Upgsxkqf8+oZd0LeVJzk7fwA1FyAcXIrfGCKqRugtk59ptPVJcnCMD+2MX02bYoP682R70w\/YWjHFN7W5wyJJ8OXIuRogSoyo8CNGn2P+aGypadUCYuCkJ\/pQZBiImfVMg\/nqEF5iZ4nuijLrXR7ONrXZkVmzTTMUTMBhdsEyuB2BPm3x1bCxvoeMqoopvmnQcVkuYmvAbib9rtrvNM\/sjVWmFy86Fwq+v56Cq1yoQrRptZ4Zsrfd1CtEsy2\/F3O0QfBeYBEqP"


Mac = "55f1f382c615eceb705b1183a9a7f5a174e788c1fca524c4119d5db545e1272a"



how can I solve this problem.

thanks.

Those API are extremely sensitive to the correct setting of parameters.


Have a look here:

https://stackoverflow.com/questions/37680361/aes-encryption-in-swift

… no one can't decrypt data that encrypted by 32 bit IV.

That’s because this task doesn’t make any sense. AES is a 128-bit block cypher [1], so the IV is always 128 bits, that is, 16 bytes. A 32-bit IV makes no sense in an AES context, and neither does a 32-byte IV.

its one of my encrypted data:

Can you be more specific about what this info means? My best guess is that:

  • IV
    is a Base64-encoded AES IV (when you decode the Base64 this you get 16 bytes, which is promising).
  • Value
    is a Base64-encoded something. Is this meant to be the plaintext? Or the cyphertext? Also, the value as you’ve shown here won’t actually decode as base64.
    $ cat tmp.b64 
    hqWeO5q9bisLhwObdlWM7nAD3nZW2SpGRoD7W1TXPI+ooOvprCw3E+Upgsxkqf8+oZd0LeVJzk7fwA1FyAcXIrfGCKqRugtk59ptPVJcnCMD+2MX02bYoP682R70w\/YWjHFN7W5wyJJ8OXIuRogSoyo8CNGn2P+aGypadUCYuCkJ\/pQZBiImfVMg\/nqEF5iZ4nuijLrXR7ONrXZkVmzTTMUTMBhdsEyuB2BPm3x1bCxvoeMqoopvmnQcVkuYmvAbib9rtrvNM\/sjVWmFy86Fwq+v56Cq1yoQrRptZ4Zsrfd1CtEsy2\/F3O0QfBeYBEqP
    $ base64 -D tmp.b64 > tmp.dat
    Invalid character in input stream.

    This that a copy’n’paste error? Or is this really not meant to be Base64?

  • Mac
    looks to be hex encoded. Is that the plaintext or the cyphertext? And if it’s hex encoded, does that imply it’s meant to be binary data? Or are you dealing with, for example, an ASCII-encoded hex string?
  • Are you using some sort of padding? Or are you guaranteeing that the plaintext size will always be an even multiple of the block size?

For examples of how to use CommonCrypto to produce results that match other security toolkits, look at the CryptoCompatibility sample code. That’s written in Objective-C but right now it seems like you’ve having more problems with the fundamentals than with the language.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

[1] Despite the 256 in the name, AES-256 is a 128-bit block cypher. In this context the 256 refers to the key size, not the block size.

how decryption AES 256 CBC with 32 bit IV in swift
 
 
Q