![JAR search and dependency download from the Maven repository](/logo.png)
nl.open.jwtdependency.org.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 java-jwt-nodependencies Show documentation
Show all versions of java-jwt-nodependencies Show documentation
This is a drop in replacement for the auth0 java-jwt library (see https://github.com/auth0/java-jwt). This jar makes sure there are no external dependencies (e.g. fasterXml, Apacha Commons) needed. This is useful when deploying to an application server (e.g. tomcat with Alfreso or Pega).
The newest version!
package org.bouncycastle.asn1.x9;
import java.math.BigInteger;
import org.bouncycastle.math.ec.ECCurve;
import org.bouncycastle.math.ec.ECFieldElement;
/**
* A class which converts integers to byte arrays, allowing padding and calculations
* to be done according the the filed size of the curve or field element involved.
*/
public class X9IntegerConverter
{
/**
* Return the curve's field size in bytes.
*
* @param c the curve of interest.
* @return the field size in bytes (rounded up).
*/
public int getByteLength(
ECCurve c)
{
return (c.getFieldSize() + 7) / 8;
}
/**
* Return the field element's field size in bytes.
*
* @param fe the field element of interest.
* @return the field size in bytes (rounded up).
*/
public int getByteLength(
ECFieldElement fe)
{
return (fe.getFieldSize() + 7) / 8;
}
/**
* Convert an integer to a byte array, ensuring it is exactly qLength long.
*
* @param s the integer to be converted.
* @param qLength the length
* @return the resulting byte array.
*/
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;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy