bouncycastle.asn1.x9.X9IntegerConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of woodlouse Show documentation
Show all versions of woodlouse Show documentation
Lightweight crypto toolkit for Android and Java 6+
The newest version!
package bouncycastle.asn1.x9;
import java.math.BigInteger;
import bouncycastle.math.ec.ECCurve;
import bouncycastle.math.ec.ECFieldElement;
public class X9IntegerConverter
{
public int getByteLength(
ECCurve c)
{
return (c.getFieldSize() + 7) / 8;
}
public int getByteLength(
ECFieldElement fe)
{
return (fe.getFieldSize() + 7) / 8;
}
public byte[] integerToBytes(
BigInteger s,
int qLength)
{
byte[] bytes = s.toByteArray();
if (qLength < bytes.length)
{
byte[] tmp = new byte[qLength];
System.arraycopy(bytes, bytes.length - tmp.length, tmp, 0, tmp.length);
return tmp;
}
else if (qLength > bytes.length)
{
byte[] tmp = new byte[qLength];
System.arraycopy(bytes, 0, tmp, tmp.length - bytes.length, bytes.length);
return tmp;
}
return bytes;
}
}