01: package org.bouncycastle.util;
02:
03: import java.math.BigInteger;
04:
05: /**
06: * BigInteger utilities.
07: */
08: public final class BigIntegers {
09: /**
10: * Return the passed in value as an unsigned byte array.
11: *
12: * @param value value to be converted.
13: * @return a byte array without a leading zero byte if present in the signed encoding.
14: */
15: public static byte[] asUnsignedByteArray(BigInteger value) {
16: byte[] bytes = value.toByteArray();
17:
18: if (bytes[0] == 0) {
19: byte[] tmp = new byte[bytes.length - 1];
20:
21: System.arraycopy(bytes, 1, tmp, 0, tmp.length);
22:
23: return tmp;
24: }
25:
26: return bytes;
27: }
28: }
|