Package com.google.crypto.tink.internal
Class BigIntegerEncoding
- java.lang.Object
-
- com.google.crypto.tink.internal.BigIntegerEncoding
-
public final class BigIntegerEncoding extends java.lang.ObjectHelper class with functions that encode and decode non-negativeBigIntegerto and frombyte[].
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.math.BigIntegerfromUnsignedBigEndianBytes(byte[] bytes)Parses aBigIntegerfrom a byte array using unsigned big-endian encoding.static byte[]toBigEndianBytes(java.math.BigInteger n)Encodes a non-negativeBigIntegerinto the minimal two's-complement representation in big-endian byte-order.static byte[]toBigEndianBytesOfFixedLength(java.math.BigInteger n, int length)Encodes a non-negativeBigIntegerinto a byte array of a specified length, using big-endian byte-order.static byte[]toUnsignedBigEndianBytes(java.math.BigInteger n)Encodes a non-negativeBigIntegerinto the minimal unsigned representation in big-endian byte-order.
-
-
-
Method Detail
-
toBigEndianBytes
public static byte[] toBigEndianBytes(java.math.BigInteger n)
Encodes a non-negativeBigIntegerinto 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[]).
-
toUnsignedBigEndianBytes
public static byte[] toUnsignedBigEndianBytes(java.math.BigInteger n)
Encodes a non-negativeBigIntegerinto the minimal unsigned representation in big-endian byte-order.In the output, the first byte is never zero. BigInteger.ZERO is encoded as empty string.
-
toBigEndianBytesOfFixedLength
public static byte[] toBigEndianBytesOfFixedLength(java.math.BigInteger n, int length) throws java.security.GeneralSecurityExceptionEncodes a non-negativeBigIntegerinto 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.
- Throws:
java.security.GeneralSecurityException
-
fromUnsignedBigEndianBytes
public static java.math.BigInteger fromUnsignedBigEndianBytes(byte[] bytes)
Parses aBigIntegerfrom a byte array using unsigned big-endian encoding.See also RFC 8017, Sec. 4.2
-
-