-
Hello, I'm trying to encrypt some data using CryptoSwift, and I need to use the noPadding function to achieve the same behavior as mbedtls_aes_crypt_cfb128 in C. I tried the following code:
However, I received the following exception: CryptoSwift.AES.Error.dataPaddingRequired. Thank in advance |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hello, I think I have figured out the issue with my previous attempt to use the noPadding function in CryptoSwift. It seems that if there's no padding, the input needs to be a multiple of 16 bits. I have updated my input array to include additional bytes so that it's a multiple of 16 bits, like this: This code now works without throwing a CryptoSwift.AES.Error.dataPaddingRequired exception. I hope this solution helps others who may encounter similar issues. Best regards. PS: |
Beta Was this translation helpful? Give feedback.
-
some modes require padding. that's the inherent feature of the block mode. if a data is not divisible by the block size, tha padding adds missing bytes. hence the requirement |
Beta Was this translation helpful? Give feedback.
Hello,
I think I have figured out the issue with my previous attempt to use the noPadding function in CryptoSwift. It seems that if there's no padding, the input needs to be a multiple of 16 bits.
I have updated my input array to include additional bytes so that it's a multiple of 16 bits, like this:
let input: Array<UInt8> = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] let encrypted: Array<UInt8> = try! AES(key: Array("secret0key000000".utf8), blockMode: CBC(iv: Array("0123456789012345".utf8)), padding: .noPadding).encrypt(input)
This code now works without throwing a CryptoSwift.AES.Error.dataPaddingRequired exception.
I hope this solution helps others who may encounter similar issues.
Best…