decrypter := cipher.NewCBCDecrypter(c, iv)
decrypted = make([]byte, len(in))
decrypter.CryptBlocks(decrypted, in)
This works great, but the resulting byte array is padded up to the next block size with un-needed data. What step am I missing to determine the actual size of the decrypted value so I can return a slice of the actual data without the padding?
Thanks!
Brian
Russ
I was thinking I could check for that case and strip out 7 * 0x07 or 6 * 0x06, etc. I know that my input strings are never going to have non-printable characters, too, so I was thinking generically I could drop any bytes values at 15 or under, since they'd be the most possible padding.
OpenSSL is doing this process automatically, both in the C library that we're using from MySQL , and the Ruby bindings to OpenSSL that we're using from our application. Dropping the bytes under 16 would work, as would checking for repeated bytes under 15. I can go look at the OpenSSL source code and see what they're doing for maximum compatibility.
I asked if I was doing something wrong or missing something because the OpenSSL C library returns a length integer that is the length of the actual decrypted string without the extra padding. I was thinking there would be a similar Go function. It's easy enough to implement, either way.
Thanks for the help.
Brian
If you do implement the framing yourself, note the possible
padding lengths must be from 1 to 16, not 0 to 15. Otherwise
you cannot unpad unambiguously.
Russ
Brian