Base32Converter checks the input wrong number of bits

Apr 17, 2012 at 8:07 PM

The Base32 encoding specification states that a inputs bit-length must be a multiple of 5. In your Base32Converter, you do the following check:

int mod = buffer.Length % 3;
if (mod != 0) {
    throw new InvalidOperationException("...");
}

This seems wrong. The bit length of a byte[] array should be buffer.Length * 8 (there are 8 bits per byte), and then you should check the bit length. This seems more correct.

int bitLength = buffer.Length * 8;
int bitsNotProvided = bitLength % 5;

if (bitsNotProvided != 0) {
    throw new InvalidOperationException("...");
}

However also, the specification states that you really should pad the input with 0's for the number of bits that were not provided. I am hoping to get your response on this, and correct me if I am wrong? I am writing my own Base32Encoding for learning purposes and for use in my own licensing scheme, but there seems to be some issues that contradict the specification in your Base32Converter.

Coordinator
Apr 18, 2012 at 11:52 PM

The Base32Converter used in Activatar is a custom implementation that serves the purpouses of generating a readable Product Key.

Please, don't use this implementation as an example of a standard. It works for this project but may be is not the best implementation for other scenarios.

I hope this answer your question.