当前位置: 首页>>代码示例>>Java>>正文


Java ECPublicKey类代码示例

本文整理汇总了Java中java.security.interfaces.ECPublicKey的典型用法代码示例。如果您正苦于以下问题:Java ECPublicKey类的具体用法?Java ECPublicKey怎么用?Java ECPublicKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ECPublicKey类属于java.security.interfaces包,在下文中一共展示了ECPublicKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ECKey

import java.security.interfaces.ECPublicKey; //导入依赖的package包/类
/**
 * Generate a new keypair using the given Java Security Provider.
 *
 * All private key operations will use the provider.
 */
public ECKey(Provider provider, SecureRandom secureRandom) {
  this.provider = provider;

  KeyPairGenerator keyPairGen = ECKeyPairGenerator.getInstance(provider, secureRandom);
  KeyPair keyPair = keyPairGen.generateKeyPair();

  this.privKey = keyPair.getPrivate();
  PublicKey pubKey = keyPair.getPublic();

  if (pubKey instanceof BCECPublicKey) {
    pub = ((BCECPublicKey) pubKey).getQ();
  } else if (pubKey instanceof ECPublicKey) {
    pub = extractPublicKey((ECPublicKey) pubKey);
  } else {
    throw new AssertionError("Expected Provider "
        + provider.getName()
        + " to produce a subtype of ECPublicKey, found "
        + pubKey.getClass());
  }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:26,代码来源:ECKey.java

示例2: extractOpenSSHPublic

import java.security.interfaces.ECPublicKey; //导入依赖的package包/类
/**
 * @param pair KeyPair to convert to an OpenSSH public key
 * @return OpenSSH-encoded pubkey
 */
public static byte[] extractOpenSSHPublic(KeyPair pair) {
	try {
		PublicKey pubKey = pair.getPublic();
		if (pubKey instanceof RSAPublicKey) {
			return RSASHA1Verify.encodeSSHRSAPublicKey((RSAPublicKey) pubKey);
		} else if (pubKey instanceof DSAPublicKey) {
			return DSASHA1Verify.encodeSSHDSAPublicKey((DSAPublicKey) pubKey);
		} else if (pubKey instanceof ECPublicKey) {
			return ECDSASHA2Verify.encodeSSHECDSAPublicKey((ECPublicKey) pubKey);
		} else if (pubKey instanceof EdDSAPublicKey) {
			return Ed25519Verify.encodeSSHEd25519PublicKey((EdDSAPublicKey) pubKey);
		} else {
			return null;
		}
	} catch (IOException e) {
		return null;
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:PubkeyUtils.java

示例3: ECKey

import java.security.interfaces.ECPublicKey; //导入依赖的package包/类
/**
 * Generate a new keypair using the given Java Security Provider.
 *
 * All private key operations will use the provider.
 */
public ECKey(Provider provider, SecureRandom secureRandom) {
    this.provider = provider;

    final KeyPairGenerator keyPairGen = ECKeyPairGenerator.getInstance(provider, secureRandom);
    final KeyPair keyPair = keyPairGen.generateKeyPair();

    this.privKey = keyPair.getPrivate();

    final PublicKey pubKey = keyPair.getPublic();
    if (pubKey instanceof BCECPublicKey) {
        pub = ((BCECPublicKey) pubKey).getQ();
    } else if (pubKey instanceof ECPublicKey) {
        pub = extractPublicKey((ECPublicKey) pubKey);
    } else {
        throw new AssertionError(
            "Expected Provider " + provider.getName() +
            " to produce a subtype of ECPublicKey, found " + pubKey.getClass());
    }
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:25,代码来源:ECKey.java

示例4: ECKey

import java.security.interfaces.ECPublicKey; //导入依赖的package包/类
/**
 * Generate a new keypair using the given Java Security Provider.
 *
 * All private key operations will use the provider.
 */
public ECKey(Provider provider, SecureRandom secureRandom) {
    this.provider = provider;

    final KeyPairGenerator keyPairGen = ECKeyPairGenerator.getInstance(provider, secureRandom);
    final KeyPair keyPair = keyPairGen.generateKeyPair();

    this.privKey = keyPair.getPrivate();
    final PublicKey pubKey = keyPair.getPublic();

    if (pubKey instanceof BCECPublicKey) {
        pub = ((BCECPublicKey) pubKey).getQ();
    } else if (pubKey instanceof ECPublicKey) {
        pub = extractPublicKey((ECPublicKey) pubKey);
    } else {
        throw new AssertionError(
            "Expected Provider " + provider.getName() +
            " to produce a subtype of ECPublicKey, found " + pubKey.getClass());
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:25,代码来源:ECKey.java

示例5: shouldSignAndVerifyWithECDSA384

import java.security.interfaces.ECPublicKey; //导入依赖的package包/类
@Test
public void shouldSignAndVerifyWithECDSA384() throws Exception {
    ECDSAAlgorithm algorithm384 = (ECDSAAlgorithm) Algorithm.ECDSA384((ECPublicKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_384, "EC"), (ECPrivateKey) readPrivateKeyFromFile(PRIVATE_KEY_FILE_384, "EC"));
    String content384 = "eyJhbGciOiJFUzM4NCJ9.eyJpc3MiOiJhdXRoMCJ9";

    for (int i = 0; i < 10; i++) {
        byte[] signature = algorithm384.sign(content384.getBytes());
        String signature384 = Base64.encodeBase64URLSafeString((signature));

        String token  = content384 + "." + signature384;
        JWT jwt = JWT.require(algorithm384).withIssuer("auth0").build();
        DecodedJWT decoded = jwt.decode(token);
        algorithm384.verify(decoded, EncodeType.Base64);
    }
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:16,代码来源:ECDSAAlgorithmTest.java

示例6: shouldDecodeECDSA384JOSE

import java.security.interfaces.ECPublicKey; //导入依赖的package包/类
@Test
public void shouldDecodeECDSA384JOSE() throws Exception {
    ECDSAAlgorithm algorithm384 = (ECDSAAlgorithm) Algorithm.ECDSA384((ECPublicKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_384, "EC"), (ECPrivateKey) readPrivateKeyFromFile(PRIVATE_KEY_FILE_384, "EC"));

    //Without padding
    byte[] joseSignature = createJOSESignature(48, false, false);
    byte[] derSignature = algorithm384.JOSEToDER(joseSignature);
    assertValidDERSignature(derSignature, 48, false, false);

    //With R padding
    joseSignature = createJOSESignature(48, true, false);
    derSignature = algorithm384.JOSEToDER(joseSignature);
    assertValidDERSignature(derSignature, 48, true, false);

    //With S padding
    joseSignature = createJOSESignature(48, false, true);
    derSignature = algorithm384.JOSEToDER(joseSignature);
    assertValidDERSignature(derSignature, 48, false, true);

    //With both paddings
    joseSignature = createJOSESignature(48, true, true);
    derSignature = algorithm384.JOSEToDER(joseSignature);
    assertValidDERSignature(derSignature, 48, true, true);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:25,代码来源:ECDSAAlgorithmTest.java

示例7: decodeECCPublicKeyX509

import java.security.interfaces.ECPublicKey; //导入依赖的package包/类
/**
 * Extract the raw bytes of the public ECC key in standard smart card format.
 * @param publicKey the key to extract the bytes of.
 * @param curveReference the reference to the standard curve of the key.
 * @return the extract bytes of the key.
 */
public static byte[] decodeECCPublicKeyX509(PublicKey publicKey, EllipticCurveParameters curveReference)
{
    byte[] publicKeyBytes = {};

    if (publicKey instanceof ECPublicKey)
    {
        final ECPoint w = ((ECPublicKey)publicKey).getW();

        final byte[] x = getStandardSizeInteger(w.getAffineX().toByteArray(), curveReference);
        final byte[] y = getStandardSizeInteger(w.getAffineY().toByteArray(), curveReference);

        publicKeyBytes = Bytes.concatenate(Bytes.bytes("04"), x, y); // Uncompressed format.
    }

    return publicKeyBytes;
}
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:23,代码来源:ECCUtils.java

示例8: shouldThrowOnSignWhenThePrivateKeyIsInvalid

import java.security.interfaces.ECPublicKey; //导入依赖的package包/类
@Test
public void shouldThrowOnSignWhenThePrivateKeyIsInvalid() throws Exception {
    exception.expect(SignatureGenerationException.class);
    exception.expectMessage("The Token's Signature couldn't be generated when signing using the Algorithm: some-algorithm");
    exception.expectCause(isA(InvalidKeyException.class));

    CryptoHelper crypto = mock(CryptoHelper.class);
    when(crypto.createSignatureFor(anyString(), any(PrivateKey.class), any(byte[].class)))
            .thenThrow(InvalidKeyException.class);

    ECPublicKey publicKey = mock(ECPublicKey.class);
    ECPrivateKey privateKey = mock(ECPrivateKey.class);
    ECDSAKeyProvider provider = ECDSAAlgorithm.providerForKeys(publicKey, privateKey);
    Algorithm algorithm = new ECDSAAlgorithm(crypto, "some-alg", "some-algorithm", 32, provider);
    algorithm.sign(ES256Header.getBytes(StandardCharsets.UTF_8));
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:17,代码来源:ECDSAAlgorithmTest.java

示例9: shouldDoECDSA512SigningWithProvidedPrivateKey

import java.security.interfaces.ECPublicKey; //导入依赖的package包/类
@Test
public void shouldDoECDSA512SigningWithProvidedPrivateKey() throws Exception {
    ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
    PrivateKey privateKey = readPrivateKeyFromFile(PRIVATE_KEY_FILE_512, "EC");
    PublicKey publicKey = readPublicKeyFromFile(PUBLIC_KEY_FILE_512, "EC");
    when(provider.getPrivateKey()).thenReturn((ECPrivateKey) privateKey);
    when(provider.getPublicKeyById(null)).thenReturn((ECPublicKey) publicKey);
    Algorithm algorithm = Algorithm.ECDSA512(provider);
    String jwtContent = String.format("%s.%s", ES512Header, auth0IssPayload);
    byte[] contentBytes = jwtContent.getBytes(StandardCharsets.UTF_8);
    byte[] signatureBytes = algorithm.sign(contentBytes);
    String jwtSignature = Base64.encodeBase64URLSafeString(signatureBytes);
    String token  = String.format("%s.%s", jwtContent, jwtSignature);

    assertThat(signatureBytes, is(notNullValue()));
    JWT jwt = JWT.require(algorithm).withIssuer("auth0").build();
    DecodedJWT decoded = jwt.decode(token);
    algorithm.verify(decoded, EncodeType.Base64);
}
 
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:20,代码来源:ECDSAAlgorithmTest.java

示例10: serverKeyExchange

import java.security.interfaces.ECPublicKey; //导入依赖的package包/类
private void serverKeyExchange(ECDH_ServerKeyExchange mesg)
        throws IOException {
    if (debug != null && Debug.isOn("handshake")) {
        mesg.print(System.out);
    }
    ECPublicKey key = mesg.getPublicKey();
    ecdh = new ECDHCrypt(key.getParams(), sslContext.getSecureRandom());
    ephemeralServerKey = key;

    // check constraints of EC PublicKey
    if (!algorithmConstraints.permits(
        EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), ephemeralServerKey)) {

        throw new SSLHandshakeException("ECDH ServerKeyExchange " +
                "does not comply to algorithm constraints");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ClientHandshaker.java

示例11: verifyECSignature

import java.security.interfaces.ECPublicKey; //导入依赖的package包/类
public static boolean verifyECSignature(String encodededData, String encodedSignedData, String encodedPublicKey) throws CryptoException
{
    try {
        KeyFactory keyFactory = KeyFactory.getInstance("EC");
        X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(Base64.decode(encodedPublicKey, Base64.DEFAULT));
        ECPublicKey publicKey = (ECPublicKey) keyFactory.generatePublic(publicKeySpec);

        Signature verificationFunction = Signature.getInstance(REST_AUTH_SIGNATURE_ALGORITHM);
        verificationFunction.initVerify(publicKey);
        verificationFunction.update(Base64.decode(encodededData, Base64.DEFAULT));

         if (verificationFunction.verify(Base64.decode(encodedSignedData, Base64.DEFAULT))) {
            return true;
         }

    } catch (NoSuchAlgorithmException | InvalidKeySpecException | InvalidKeyException |
             SignatureException e)
    {
        throw new CryptoException("Unable to verify signature: " + e.getMessage());
    }

    return false;
}
 
开发者ID:thiscitizenis,项目名称:citizen-sdk-android,代码行数:24,代码来源:CryptoService.java

示例12: createServerTokenHeader

import java.security.interfaces.ECPublicKey; //导入依赖的package包/类
private JWSHeader createServerTokenHeader(ECPublicKey serverPublicKey) {
    if (!serverPublicKey.getFormat().equals("X.509")) {
        throw new RuntimeException(String.format(
                "Server public key is not in X.509 format! Got %s instead",
                serverPublicKey.getFormat()
        ));
    }

    return new JWSHeader(
            JWSAlgorithm.ES384,
            null,
            null,
            null,
            null,
            null,
            URI.create(getServerPublicKeyBase64((ECPublicKey) serverKeyPair.getPublic())),
            null,
            null,
            null,
            null,
            null,
            null
    );
}
 
开发者ID:JungleTree,项目名称:JungleTree,代码行数:25,代码来源:JwtTokenFactory.java

示例13: getSigAlgId

import java.security.interfaces.ECPublicKey; //导入依赖的package包/类
public static AlgorithmIdentifier getSigAlgId(PublicKey pubKey, HashAlgoType hashAlgo,
        SignatureAlgoControl algoControl) throws NoSuchAlgorithmException {
    ParamUtil.requireNonNull("hashAlgo", hashAlgo);

    if (pubKey instanceof RSAPublicKey) {
        boolean rsaMgf1 = (algoControl == null) ? false : algoControl.isRsaMgf1();
        return getRSASigAlgId(hashAlgo, rsaMgf1);
    } else if (pubKey instanceof ECPublicKey) {
        boolean dsaPlain = (algoControl == null) ? false : algoControl.isDsaPlain();
        boolean gm =  (algoControl == null) ? false : algoControl.isGm();
        return getECSigAlgId(hashAlgo, dsaPlain, gm);
    } else if (pubKey instanceof DSAPublicKey) {
        return getDSASigAlgId(hashAlgo);
    } else {
        throw new NoSuchAlgorithmException("Unknown public key '"
                + pubKey.getClass().getName());
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:19,代码来源:AlgorithmUtil.java

示例14: P11PrivateKey

import java.security.interfaces.ECPublicKey; //导入依赖的package包/类
public P11PrivateKey(P11CryptService p11CryptService, P11EntityIdentifier identityId)
        throws P11TokenException {
    this.p11CryptService = ParamUtil.requireNonNull("identityId", p11CryptService);
    this.identityId = ParamUtil.requireNonNull("entityId", identityId);

    this.publicKey = p11CryptService.getIdentity(identityId).publicKey();

    if (this.publicKey instanceof RSAPublicKey) {
        algorithm = "RSA";
        keysize = ((RSAPublicKey) publicKey).getModulus().bitLength();
    } else if (this.publicKey instanceof DSAPublicKey) {
        algorithm = "DSA";
        keysize = ((DSAPublicKey) publicKey).getParams().getP().bitLength();
    } else if (this.publicKey instanceof ECPublicKey) {
        algorithm = "EC";
        keysize = ((ECPublicKey) publicKey).getParams().getCurve().getField().getFieldSize();
    } else {
        throw new P11TokenException("unknown public key: " + publicKey);
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:21,代码来源:P11PrivateKey.java

示例15: getPublicKey

import java.security.interfaces.ECPublicKey; //导入依赖的package包/类
/**
 * Returns the ECPublicKey instance from its encoded raw bytes. 
 * The first byte has the fixed value 0x04 indicating the uncompressed form.
 * Therefore, the byte array must be of form: [0x04, x coord of point (32 bytes), y coord of point (32 bytes)]
 * 
 * @param publicKeyBytes The byte array representing the encoded raw bytes of the public key
 * @return The ECPublicKey instance
 */
public static ECPublicKey getPublicKey(byte[] publicKeyBytes) {
	// First we separate x and y of coordinates into separate variables
    byte[] x = new byte[32];
    byte[] y = new byte[32];
    System.arraycopy(publicKeyBytes, 1, x, 0, 32);
    System.arraycopy(publicKeyBytes, 33, y, 0, 32);
    
    try {
		KeyFactory kf = KeyFactory.getInstance("EC");
		
		AlgorithmParameters parameters = AlgorithmParameters.getInstance("EC");
		parameters.init(new ECGenParameterSpec("secp256r1"));
		ECParameterSpec ecParameterSpec = parameters.getParameterSpec(ECParameterSpec.class);
		
		ECPublicKeySpec ecPublicKeySpec = new ECPublicKeySpec(new ECPoint(new BigInteger(x), new BigInteger(y)), ecParameterSpec);
		ECPublicKey ecPublicKey = (ECPublicKey) kf.generatePublic(ecPublicKeySpec);
		return ecPublicKey;
    } catch (NoSuchAlgorithmException | InvalidParameterSpecException | InvalidKeySpecException e) {
		getLogger().error(e.getClass().getSimpleName() + " occurred when trying to get public key from raw bytes", e);
        return null;
	}
}
 
开发者ID:V2GClarity,项目名称:RISE-V2G,代码行数:31,代码来源:SecurityUtils.java


注:本文中的java.security.interfaces.ECPublicKey类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。