private byte[] padPassword(byte[] password) {

        if (password == null) {
            password = new byte[0];
        }

        // Step 1: Pad or truncate the password string to exactly 32 bytes. If
        // the password string is more than 32 bytes long, use only its first 32
        // bytes; if it is less than 32 bytes long, pad it by appending the
        // required number of additional bytes from the beginning of the
        // following padding string:
        // < 28 BF 4E 5E 4E 75 8A 41 64 00 4E 56 FF FA 01 08
        //   2E 2E 00 B6 D0 68 3E 80 2F 0C A9 FE 64 53 69 7A >
        // That is, if the password string is n bytes long, append the first 32
        // â n bytes of the padding string to the end of the password string. If
        // the password string is empty (zero-length), meaning there is no user
        // password, substitute the entire padding string in its place.

        byte[] padded = new byte[32];
        // limit password to 32 bytes
        final int numContributingPasswordBytes =
                password.length > padded.length ?
                padded.length : password.length;
        System.arraycopy(password, 0, padded, 0, numContributingPasswordBytes);
        // Copy padding
        if (password.length < padded.length) {
            System.arraycopy(PW_PADDING, 0, padded, password.length,
                    padded.length - password.length);
        }
        return padded;
    }