Search in sources :

Example 11 with X9IntegerConverter

use of org.spongycastle.asn1.x9.X9IntegerConverter in project web3sdk by FISCO-BCOS.

the class Sign method decompressKey.

/**
 * Decompress a compressed public key (x co-ord and low-bit of y-coord).
 */
private static ECPoint decompressKey(BigInteger xBN, boolean yBit) {
    X9IntegerConverter x9 = new X9IntegerConverter();
    byte[] compEnc = x9.integerToBytes(xBN, 1 + x9.getByteLength(CURVE.getCurve()));
    compEnc[0] = (byte) (yBit ? 0x03 : 0x02);
    return CURVE.getCurve().decodePoint(compEnc);
}
Also used : X9IntegerConverter(org.bouncycastle.asn1.x9.X9IntegerConverter)

Example 12 with X9IntegerConverter

use of org.spongycastle.asn1.x9.X9IntegerConverter in project aion by aionnetwork.

the class ECKeySecp256k1 method decompressKey.

/**
 * Decompress a compressed public key (x co-ord and low-bit of y-coord).
 *
 * @param xBN -
 * @param yBit -
 * @return -
 */
private ECPoint decompressKey(BigInteger xBN, boolean yBit) {
    X9IntegerConverter x9 = new X9IntegerConverter();
    byte[] compEnc = x9.integerToBytes(xBN, 1 + x9.getByteLength(CURVE.getCurve()));
    compEnc[0] = (byte) (yBit ? 0x03 : 0x02);
    return CURVE.getCurve().decodePoint(compEnc);
}
Also used : X9IntegerConverter(org.spongycastle.asn1.x9.X9IntegerConverter)

Example 13 with X9IntegerConverter

use of org.spongycastle.asn1.x9.X9IntegerConverter in project keycloak by keycloak.

the class ECDSASignatureProvider method asn1derToConcatenatedRS.

public static byte[] asn1derToConcatenatedRS(final byte[] derEncodedSignatureValue, int signLength) throws IOException {
    int len = signLength / 2;
    ASN1InputStream asn1InputStream = new ASN1InputStream(derEncodedSignatureValue);
    ASN1Primitive asn1Primitive = asn1InputStream.readObject();
    asn1InputStream.close();
    ASN1Sequence asn1Sequence = (ASN1Sequence.getInstance(asn1Primitive));
    ASN1Integer rASN1 = (ASN1Integer) asn1Sequence.getObjectAt(0);
    ASN1Integer sASN1 = (ASN1Integer) asn1Sequence.getObjectAt(1);
    X9IntegerConverter x9IntegerConverter = new X9IntegerConverter();
    byte[] r = x9IntegerConverter.integerToBytes(rASN1.getValue(), len);
    byte[] s = x9IntegerConverter.integerToBytes(sASN1.getValue(), len);
    byte[] concatenatedSignatureValue = new byte[signLength];
    System.arraycopy(r, 0, concatenatedSignatureValue, 0, len);
    System.arraycopy(s, 0, concatenatedSignatureValue, len, len);
    return concatenatedSignatureValue;
}
Also used : ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) X9IntegerConverter(org.bouncycastle.asn1.x9.X9IntegerConverter) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive)

Aggregations

X9IntegerConverter (org.bouncycastle.asn1.x9.X9IntegerConverter)7 X9IntegerConverter (org.spongycastle.asn1.x9.X9IntegerConverter)6 IOException (java.io.IOException)3 ECParameterSpec (java.security.spec.ECParameterSpec)3 ECPoint (java.security.spec.ECPoint)3 EllipticCurve (java.security.spec.EllipticCurve)3 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)3 DERBitString (org.bouncycastle.asn1.DERBitString)3 DEROctetString (org.bouncycastle.asn1.DEROctetString)3 X962Parameters (org.bouncycastle.asn1.x9.X962Parameters)3 X9ECParameters (org.bouncycastle.asn1.x9.X9ECParameters)3 X9ECPoint (org.bouncycastle.asn1.x9.X9ECPoint)3 ECNamedCurveSpec (org.bouncycastle.jce.spec.ECNamedCurveSpec)3 ECCurve (org.bouncycastle.math.ec.ECCurve)3 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)2 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)2 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)1 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)1 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)1 DERObject (org.bouncycastle.asn1.DERObject)1