/** * Base64-encodes the specified big integer, without the sign bit. * * @param bigInt The big integer to encode. Must not be {@code null}. * * @return The resulting Base64 object. */ public static Base64 encode(final BigInteger bigInt) { return encode(BigIntegerUtils.toBytesUnsigned(bigInt)); }
/** * Base64URL-encodes the specified big integer, without the sign bit. * * @param bigInt The big integer to encode. Must not be {@code null}. * * @return The resulting Base64URL object. */ public static Base64URL encode(final BigInteger bigInt) { return encode(BigIntegerUtils.toBytesUnsigned(bigInt)); }
/** * Returns the Base64URL encoding of the specified elliptic curve 'x', * 'y' or 'd' coordinate, with leading zero padding up to the specified * field size in bits. * * @param fieldSize The field size in bits. * @param coordinate The elliptic curve coordinate. Must not be * {@code null}. * * @return The Base64URL-encoded coordinate, with leading zero padding * up to the curve's field size. */ public static Base64URL encodeCoordinate(final int fieldSize, final BigInteger coordinate) { final byte[] notPadded = BigIntegerUtils.toBytesUnsigned(coordinate); int bytesToOutput = (fieldSize + 7)/8; if (notPadded.length >= bytesToOutput) { // Greater-than check to prevent exception on malformed // key below return Base64URL.encode(notPadded); } final byte[] padded = new byte[bytesToOutput]; System.arraycopy(notPadded, 0, padded, bytesToOutput - notPadded.length, notPadded.length); return Base64URL.encode(padded); }