public final class BigIntegerEncoding extends Object
BigInteger to
and from byte[].| Modifier and Type | Method and Description |
|---|---|
static BigInteger |
fromUnsignedBigEndianBytes(byte[] bytes)
Parses a
BigInteger from a byte array using unsigned big-endian encoding. |
static byte[] |
toBigEndianBytes(BigInteger n)
Encodes a non-negative
BigInteger into the minimal two's-complement
representation in big-endian byte-order. |
static byte[] |
toBigEndianBytesOfFixedLength(BigInteger n,
int length)
Encodes a non-negative
BigInteger into a byte array of a specified length,
using big-endian byte-order. |
public static byte[] toBigEndianBytes(BigInteger n)
BigInteger into the minimal two's-complement
representation in big-endian byte-order.
The most significant bit of the first byte is the sign bit, which is always 0 because the
input number is non-negative. Because of that, the output is at the same time also an unsigned
big-endian encoding that may have an additional zero byte at the beginning, and can be parsed
with fromUnsignedBigEndianBytes(byte[]).
public static byte[] toBigEndianBytesOfFixedLength(BigInteger n, int length) throws GeneralSecurityException
BigInteger into a byte array of a specified length,
using big-endian byte-order.
See also RFC 8017, Sec. 4.2
throws a GeneralSecurityException if the number is negative or length is too short.
GeneralSecurityExceptionpublic static BigInteger fromUnsignedBigEndianBytes(byte[] bytes)
BigInteger from a byte array using unsigned big-endian encoding.
See also RFC 8017, Sec. 4.2