java.security.spec.ECPoint.getAffineX()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(75)

本文整理了Java中java.security.spec.ECPoint.getAffineX()方法的一些代码示例,展示了ECPoint.getAffineX()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ECPoint.getAffineX()方法的具体详情如下:
包路径:java.security.spec.ECPoint
类名称:ECPoint
方法名:getAffineX

ECPoint.getAffineX介绍

[英]Returns the x-coordinate.
[中]返回x坐标。

代码示例

代码示例来源:origin: hierynomus/sshj

/**
 * SECG 2.3.3 ECPoint to Octet String
 */
public static byte[] getEncoded(ECPoint point, EllipticCurve curve) {
  int elementSize = getElementSize(curve);
  byte[] M = new byte[2 * elementSize + 1];
  M[0] = 0x04;
  byte[] xBytes = stripLeadingZeroes(point.getAffineX().toByteArray());
  byte[] yBytes = stripLeadingZeroes(point.getAffineY().toByteArray());
  System.arraycopy(xBytes, 0, M, 1 + elementSize - xBytes.length, xBytes.length);
  System.arraycopy(yBytes, 0, M, 1 + 2 * elementSize - yBytes.length, yBytes.length);
  return M;
}

代码示例来源:origin: ethereum/ethereumj

private static ECPoint extractPublicKey(final ECPublicKey ecPublicKey) {
 final java.security.spec.ECPoint publicPointW = ecPublicKey.getW();
 final BigInteger xCoord = publicPointW.getAffineX();
 final BigInteger yCoord = publicPointW.getAffineY();
 return CURVE.getCurve().createPoint(xCoord, yCoord);
}

代码示例来源:origin: wildfly/wildfly

static JsonObject getJwk(PublicKey publicKey, String algHeader) {
  if (publicKey instanceof RSAPublicKey) {
    RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKey;
    return Json.createObjectBuilder()
        .add(EXPONENT, base64UrlEncode(rsaPublicKey.getPublicExponent().toByteArray()))
        .add(KEY_TYPE, "RSA")
        .add(MODULUS, base64UrlEncode(modulusToByteArray(rsaPublicKey.getModulus())))
        .build();
  } else if (publicKey instanceof ECPublicKey) {
    ECPublicKey ecPublicKey = (ECPublicKey) publicKey;
    int fieldSize = ecPublicKey.getParams().getCurve().getField().getFieldSize();
    return Json.createObjectBuilder()
        .add(CURVE, getCurveParameterFromAlgHeader(algHeader))
        .add(KEY_TYPE, "EC")
        .add(X_COORDINATE, base64UrlEncode(coordinateToByteArray(fieldSize, ecPublicKey.getW().getAffineX())))
        .add(Y_COORDINATE, base64UrlEncode(coordinateToByteArray(fieldSize, ecPublicKey.getW().getAffineY())))
        .build();
  } else {
    throw acme.unsupportedAcmeAccountPublicKeyType(publicKey.getAlgorithm());
  }
}

代码示例来源:origin: i2p/i2p.i2p

private static ECPoint doublePoint(ECPoint r, EllipticCurve curve) {
  if (r.equals(ECPoint.POINT_INFINITY)) 
    return r;
  BigInteger slope = (r.getAffineX().pow(2)).multiply(THREE);
  slope = slope.add(curve.getA());
  BigInteger prime = ((ECFieldFp) curve.getField()).getP();
  // use NBI modInverse();
  BigInteger tmp = r.getAffineY().multiply(TWO);
  tmp = new NativeBigInteger(tmp);
  slope = slope.multiply(tmp.modInverse(prime));
  BigInteger xOut = slope.pow(2).subtract(r.getAffineX().multiply(TWO)).mod(prime);
  BigInteger yOut = (r.getAffineY().negate()).add(slope.multiply(r.getAffineX().subtract(xOut))).mod(prime);
  ECPoint out = new ECPoint(xOut, yOut);
  return out;
}

代码示例来源:origin: i2p/i2p.i2p

private static ECPoint addPoint(ECPoint r, ECPoint s, EllipticCurve curve) {
  if (r.equals(s))
    return doublePoint(r, curve);
  else if (r.equals(ECPoint.POINT_INFINITY))
    return s;
  else if (s.equals(ECPoint.POINT_INFINITY))
    return r;
  BigInteger prime = ((ECFieldFp) curve.getField()).getP();
  // use NBI modInverse();
  BigInteger tmp = r.getAffineX().subtract(s.getAffineX());
  tmp = new NativeBigInteger(tmp);
  BigInteger slope = (r.getAffineY().subtract(s.getAffineY())).multiply(tmp.modInverse(prime)).mod(prime);
  slope = new NativeBigInteger(slope);
  BigInteger xOut = (slope.modPow(TWO, prime).subtract(r.getAffineX())).subtract(s.getAffineX()).mod(prime);
  BigInteger yOut = s.getAffineY().negate().mod(prime);
  yOut = yOut.add(slope.multiply(s.getAffineX().subtract(xOut))).mod(prime);
  ECPoint out = new ECPoint(xOut, yOut);
  return out;
}

代码示例来源:origin: i2p/i2p.i2p

public static SigningPublicKey fromJavaKey(ECPublicKey pk, SigType type)
             throws GeneralSecurityException {
  ECPoint w = pk.getW();
  BigInteger x = w.getAffineX();
  BigInteger y = w.getAffineY();
  int len = type.getPubkeyLen();
  byte[] b = combine(x, y, len);
  return new SigningPublicKey(type, b);
}

代码示例来源:origin: com.madgag.spongycastle/pkix

private static org.spongycastle.math.ec.ECPoint convertPoint(
  ECCurve curve,
  java.security.spec.ECPoint point)
{
  return curve.createPoint(point.getAffineX(), point.getAffineY());
}

代码示例来源:origin: org.apache.santuario/xmlsec

public static byte[] encodePoint(ECPoint ecPoint, EllipticCurve ellipticCurve) {
  int size = (ellipticCurve.getField().getFieldSize() + 7) / 8;
  byte affineXBytes[] = stripLeadingZeros(ecPoint.getAffineX().toByteArray());
  byte affineYBytes[] = stripLeadingZeros(ecPoint.getAffineY().toByteArray());
  byte encodedBytes[] = new byte[size * 2 + 1];
  encodedBytes[0] = 0x04; //uncompressed
  System.arraycopy(affineXBytes, 0, encodedBytes, size - affineXBytes.length + 1, affineXBytes.length);
  System.arraycopy(affineYBytes, 0, encodedBytes, encodedBytes.length - affineYBytes.length, affineYBytes.length);
  return encodedBytes;
}

代码示例来源:origin: org.apache.sshd/sshd-common

public static byte[] encodeECPoint(ECPoint group, EllipticCurve curve) {
  // M has len 2 ceil(log_2(q)/8) + 1 ?
  int elementSize = (curve.getField().getFieldSize() + 7) / 8;
  byte[] m = new byte[2 * elementSize + 1];
  // Uncompressed format
  m[0] = 0x04;
  byte[] affineX = removeLeadingZeroes(group.getAffineX().toByteArray());
  System.arraycopy(affineX, 0, m, 1 + elementSize - affineX.length, affineX.length);
  byte[] affineY = removeLeadingZeroes(group.getAffineY().toByteArray());
  System.arraycopy(affineY, 0, m, 1 + elementSize + elementSize - affineY.length, affineY.length);
  return m;
}

代码示例来源:origin: org.xbib/sshd-common

public static byte[] encodeECPoint(ECPoint group, EllipticCurve curve) {
  // M has len 2 ceil(log_2(q)/8) + 1 ?
  int elementSize = (curve.getField().getFieldSize() + 7) / 8;
  byte[] m = new byte[2 * elementSize + 1];
  // Uncompressed format
  m[0] = 0x04;
  byte[] affineX = removeLeadingZeroes(group.getAffineX().toByteArray());
  System.arraycopy(affineX, 0, m, 1 + elementSize - affineX.length, affineX.length);
  byte[] affineY = removeLeadingZeroes(group.getAffineY().toByteArray());
  System.arraycopy(affineY, 0, m, 1 + elementSize + elementSize - affineY.length, affineY.length);
  return m;
}

代码示例来源:origin: jenkinsci/trilead-ssh2

private static byte[] encodePoint(ECPoint group, EllipticCurve curve) {
  int elementSize = (curve.getField().getFieldSize() + 7) / 8;
  byte[] encodedPoint = new byte[2 * elementSize + 1];
  encodedPoint[0] = 0x04;
  byte[] affineX = removeLeadingZeroes(group.getAffineX().toByteArray());
  System.arraycopy(affineX, 0, encodedPoint, 1 + elementSize - affineX.length, affineX.length);
  byte[] affineY = removeLeadingZeroes(group.getAffineY().toByteArray());
  System.arraycopy(affineY, 0, encodedPoint, 1 + elementSize + elementSize - affineY.length, affineY.length);
  return encodedPoint;
}

代码示例来源:origin: org.xipki/security

public static byte[] getUncompressedEncodedECPoint(ECPoint point, int orderBitLength) {
 int orderByteLength = (orderBitLength + 7) / 8;
 byte[] keyData = new byte[1 + orderByteLength * 2];
 keyData[0] = 4;
 unsignedByteArrayCopy(keyData, 1, orderByteLength, point.getAffineX());
 unsignedByteArrayCopy(keyData, 1 + orderByteLength, orderByteLength, point.getAffineY());
 return keyData;
}

代码示例来源:origin: com.bugvm/bugvm-rt

public static OpenSSLECPointContext getInstance(int curveType, OpenSSLECGroupContext group,
      ECPoint javaPoint) {
    OpenSSLECPointContext point = new OpenSSLECPointContext(group,
        NativeCrypto.EC_POINT_new(group.getContext()));
    NativeCrypto.EC_POINT_set_affine_coordinates(group.getContext(),
        point.getContext(), javaPoint.getAffineX().toByteArray(),
        javaPoint.getAffineY().toByteArray());
    return point;
  }
}

代码示例来源:origin: CryptoKass/dilithium

private static ECPoint extractPublicKey(final ECPublicKey ecPublicKey) {
  final java.security.spec.ECPoint publicPointW = ecPublicKey.getW();
  final BigInteger xCoord = publicPointW.getAffineX();
  final BigInteger yCoord = publicPointW.getAffineY();
  return CURVE.getCurve().createPoint(xCoord, yCoord);
}

代码示例来源:origin: apache/cxf

public static JsonWebKey fromECPublicKey(ECPublicKey pk, String curve, String kid) {
  JsonWebKey jwk = prepareECJwk(curve, kid);
  jwk.setProperty(JsonWebKey.EC_X_COORDINATE,
          Base64UrlUtility.encode(pk.getW().getAffineX().toByteArray()));
  jwk.setProperty(JsonWebKey.EC_Y_COORDINATE,
          Base64UrlUtility.encode(pk.getW().getAffineY().toByteArray()));
  return jwk;
}
public static JsonWebKey fromECPrivateKey(ECPrivateKey pk, String curve) {

代码示例来源:origin: ibinti/bugvm

public static com.bugvm.bouncycastle.math.ec.ECPoint convertPoint(
    ECCurve curve,
    ECPoint point,
    boolean withCompression)
  {
    return curve.createPoint(point.getAffineX(), point.getAffineY(), withCompression);
  }
}

代码示例来源:origin: com.alibaba.middleware/termd-core

public static void assertECPointEquals(String message, ECPoint expected, ECPoint actual) {
  if (expected == actual) {
    return;
  }
  assertEquals(message + "[x]", expected.getAffineX(), actual.getAffineX());
  assertEquals(message + "[y]", expected.getAffineY(), actual.getAffineY());
}

代码示例来源:origin: com.madgag.spongycastle/prov

public static org.spongycastle.math.ec.ECPoint convertPoint(
    ECCurve curve,
    ECPoint point,
    boolean withCompression)
  {
    return curve.createPoint(point.getAffineX(), point.getAffineY());
  }
}

代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on

public static org.bouncycastle.math.ec.ECPoint convertPoint(
  ECCurve curve,
  ECPoint point,
  boolean withCompression)
{
  return curve.createPoint(point.getAffineX(), point.getAffineY());
}

代码示例来源:origin: wolpi/prim-ftpd

protected void assertsEcdsaKey(ECPublicKey pubKey) {
  final String x = "48439561293906451759052585252797914202762949526041747995844080717082404635286";
  final String y = "36134250956749795798585127919587881956611106672985015071877198253568414405109";
  Assert.assertEquals(new BigInteger(x), pubKey.getParams().getGenerator().getAffineX());
  Assert.assertEquals(new BigInteger(y), pubKey.getParams().getGenerator().getAffineY());
}

相关文章

微信公众号

最新文章

更多