Search in sources :

Example 71 with ECPoint

use of java.security.spec.ECPoint in project j2objc by google.

the class ECPointTest method testGetAffineY01.

/**
 * Test #1 for <code>getAffineY()</code> method<br>
 * Assertion: returns affine <code>y</code> coordinate<br>
 * Test preconditions: <code>ECPoint</code> instance
 * created using valid parameters<br>
 * Expected: must return affine <code>y</code> coordinate
 * which is equal to the one passed to the constructor;
 * (both must refer the same object)
 */
public final void testGetAffineY01() {
    BigInteger y = BigInteger.valueOf(23456L);
    ECPoint p = new ECPoint(BigInteger.valueOf(-23456L), y);
    BigInteger yRet = p.getAffineY();
    assertEquals(y, yRet);
    assertSame(y, yRet);
}
Also used : BigInteger(java.math.BigInteger) ECPoint(java.security.spec.ECPoint)

Example 72 with ECPoint

use of java.security.spec.ECPoint in project j2objc by google.

the class ECPointTest method testGetAffineX01.

/**
 * Test #1 for <code>getAffineX()</code> method<br>
 * Assertion: returns affine <code>x</code> coordinate<br>
 * Test preconditions: <code>ECPoint</code> instance
 * created using valid parameters<br>
 * Expected: must return affine <code>x</code> coordinate
 * which is equal to the one passed to the constructor;
 * (both must refer the same object)
 */
public final void testGetAffineX01() {
    BigInteger x = BigInteger.valueOf(-23456L);
    ECPoint p = new ECPoint(x, BigInteger.valueOf(23456L));
    BigInteger xRet = p.getAffineX();
    assertEquals(x, xRet);
    assertSame(x, xRet);
}
Also used : BigInteger(java.math.BigInteger) ECPoint(java.security.spec.ECPoint)

Example 73 with ECPoint

use of java.security.spec.ECPoint in project j2objc by google.

the class ECPublicKeySpecTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    ECPoint ecpoint = new ECPoint(BigInteger.valueOf(1), BigInteger.valueOf(1));
    EllipticCurve curve = new EllipticCurve(new ECFieldF2m(2), BigInteger.valueOf(1), BigInteger.valueOf(1));
    w = new ECPoint(BigInteger.valueOf(1), BigInteger.valueOf(1));
    params = new ECParameterSpec(curve, ecpoint, BigInteger.valueOf(1), 1);
    ecpks = new ECPublicKeySpec(w, params);
}
Also used : EllipticCurve(java.security.spec.EllipticCurve) ECParameterSpec(java.security.spec.ECParameterSpec) ECFieldF2m(java.security.spec.ECFieldF2m) ECPoint(java.security.spec.ECPoint) ECPublicKeySpec(java.security.spec.ECPublicKeySpec)

Example 74 with ECPoint

use of java.security.spec.ECPoint in project cxf by apache.

the class CryptoUtils method getECPublicKey.

public static ECPublicKey getECPublicKey(String curve, byte[] xPoint, byte[] yPoint) {
    try {
        ECParameterSpec params = getECParameterSpec(curve, false);
        ECPoint ecPoint = new ECPoint(toBigInteger(xPoint), toBigInteger(yPoint));
        ECPublicKeySpec keySpec = new ECPublicKeySpec(ecPoint, params);
        KeyFactory kf = KeyFactory.getInstance("EC");
        return (ECPublicKey) kf.generatePublic(keySpec);
    } catch (Exception ex) {
        throw new SecurityException(ex);
    }
}
Also used : ECPublicKey(java.security.interfaces.ECPublicKey) ECParameterSpec(java.security.spec.ECParameterSpec) ECPoint(java.security.spec.ECPoint) ECPublicKeySpec(java.security.spec.ECPublicKeySpec) KeyFactory(java.security.KeyFactory) DestroyFailedException(javax.security.auth.DestroyFailedException)

Example 75 with ECPoint

use of java.security.spec.ECPoint in project hutool by looly.

the class BCUtil method decodeECPoint.

/**
 * 解码恢复EC压缩公钥,支持Base64和Hex编码,(基于BouncyCastle)
 *
 * @param encodeByte 压缩公钥
 * @param curveName  EC曲线名,例如{@link SmUtil#SM2_DOMAIN_PARAMS}
 * @return 公钥
 * @since 4.4.4
 */
public static PublicKey decodeECPoint(byte[] encodeByte, String curveName) {
    final X9ECParameters x9ECParameters = ECUtil.getNamedCurveByName(curveName);
    final ECCurve curve = x9ECParameters.getCurve();
    final ECPoint point = EC5Util.convertPoint(curve.decodePoint(encodeByte));
    // 根据曲线恢复公钥格式
    final ECNamedCurveSpec ecSpec = new ECNamedCurveSpec(curveName, curve, x9ECParameters.getG(), x9ECParameters.getN());
    return KeyUtil.generatePublicKey("EC", new ECPublicKeySpec(point, ecSpec));
}
Also used : X9ECParameters(org.bouncycastle.asn1.x9.X9ECParameters) ECCurve(org.bouncycastle.math.ec.ECCurve) ECPoint(java.security.spec.ECPoint) ECPublicKeySpec(java.security.spec.ECPublicKeySpec) ECNamedCurveSpec(org.bouncycastle.jce.spec.ECNamedCurveSpec)

Aggregations

ECPoint (java.security.spec.ECPoint)111 ECParameterSpec (java.security.spec.ECParameterSpec)56 BigInteger (java.math.BigInteger)54 ECPublicKeySpec (java.security.spec.ECPublicKeySpec)36 ECPublicKey (java.security.interfaces.ECPublicKey)31 EllipticCurve (java.security.spec.EllipticCurve)31 KeyPair (java.security.KeyPair)20 ECPrivateKey (java.security.interfaces.ECPrivateKey)20 PublicKey (java.security.PublicKey)17 ECFieldFp (java.security.spec.ECFieldFp)17 ECGenParameterSpec (java.security.spec.ECGenParameterSpec)16 Test (org.junit.Test)16 KeyFactory (java.security.KeyFactory)15 KeyPairGenerator (java.security.KeyPairGenerator)14 AlgorithmParameters (java.security.AlgorithmParameters)13 GeneralSecurityException (java.security.GeneralSecurityException)12 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)11 KeySpec (java.security.spec.KeySpec)11 IOException (java.io.IOException)10 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)9