The following lines ...
if (*pkcs7 != kCCOptionECBMode) {
if ((plainTextBufferSize % kChosenCipherBlockSize) == 0) {
*pkcs7 = 0x0000;
} else {
*pkcs7 = kCCOptionPKCS7Padding;
}
}
... are the culprits of my problem. To solve this problem, I just had to comment on them.
As far as I can tell, the encryption process was not a complement on the encryption side, but then still expected to populate on the decryption side, as a result of which the decryption process failed (which, as a rule, I experienced).
Always use kCCOptionPKCS7Paddingfor encryption / decryption works for me so far, for strings that satisfy length % 16 == 0and those that do not. And, again, this is a modification of the SecKeyWrappersample code class CryptoExercise. Not sure how this will affect you with the help of CommonCryptowrapping machines.
source
share