01: package org.bouncycastle.asn1.x9;
02:
03: import org.bouncycastle.math.ec.ECCurve;
04: import org.bouncycastle.math.ec.ECFieldElement;
05:
06: import java.math.BigInteger;
07:
08: public class X9IntegerConverter {
09: public int getByteLength(ECCurve c) {
10: return (c.getFieldSize() + 7) / 8;
11: }
12:
13: public int getByteLength(ECFieldElement fe) {
14: return (fe.getFieldSize() + 7) / 8;
15: }
16:
17: public byte[] integerToBytes(BigInteger s, int qLength) {
18: byte[] bytes = s.toByteArray();
19:
20: if (qLength < bytes.length) {
21: byte[] tmp = new byte[qLength];
22:
23: System.arraycopy(bytes, bytes.length - tmp.length, tmp, 0,
24: tmp.length);
25:
26: return tmp;
27: } else if (qLength > bytes.length) {
28: byte[] tmp = new byte[qLength];
29:
30: System.arraycopy(bytes, 0, tmp, tmp.length - bytes.length,
31: bytes.length);
32:
33: return tmp;
34: }
35:
36: return bytes;
37: }
38: }
|