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


Java ECGenParameterSpec类代码示例

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


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

示例1: testEciesBasic

import java.security.spec.ECGenParameterSpec; //导入依赖的package包/类
/**
 * Check that key agreement using ECIES works. This example does not specify an IESParametersSpec.
 * BouncyCastle v.1.52 uses the following algorithms: KDF2 with SHA1 for the key derivation
 * AES-CBC with PKCS #5 padding. HMAC-SHA1 with a 20 byte digest. The AES and the HMAC key are
 * both 128 bits.
 */
@SuppressWarnings("InsecureCryptoUsage")
@Test
public void testEciesBasic() throws Exception {
  ECGenParameterSpec ecSpec = new ECGenParameterSpec("secp256r1");
  KeyPairGenerator kf = KeyPairGenerator.getInstance("EC");
  kf.initialize(ecSpec);
  KeyPair keyPair = kf.generateKeyPair();
  PrivateKey priv = keyPair.getPrivate();
  PublicKey pub = keyPair.getPublic();
  byte[] message = "Hello".getBytes("UTF-8");
  Cipher ecies = Cipher.getInstance("ECIESwithAES-CBC");
  ecies.init(Cipher.ENCRYPT_MODE, pub);
  byte[] ciphertext = ecies.doFinal(message);
  System.out.println("testEciesBasic:" + TestUtil.bytesToHex(ciphertext));
  ecies.init(Cipher.DECRYPT_MODE, priv, ecies.getParameters());
  byte[] decrypted = ecies.doFinal(ciphertext);
  assertEquals(TestUtil.bytesToHex(message), TestUtil.bytesToHex(decrypted));
}
 
开发者ID:google,项目名称:wycheproof,代码行数:25,代码来源:EciesTest.java

示例2: ServerHandshakePacket

import java.security.spec.ECGenParameterSpec; //导入依赖的package包/类
public ServerHandshakePacket(BedrockPlayer p) {
    super(PacketRegistry.NetworkType.SERVER_TO_CLIENT_HANDSHAKE_PACKET);

    try {
        KeyPairGenerator generator = KeyPairGenerator.getInstance("EC");
        generator.initialize(new ECGenParameterSpec("secp384r1"));
        KeyPair serverKeyPair = generator.generateKeyPair();

        byte[] token = Security.generateRandomToken();
        byte[] serverKey = Security.getServerKey(serverKeyPair, token);
        p.enableEncryption(serverKey);

        publicKey = serverKeyPair;
        serverToken = token;
    } catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | InvalidKeyException e) {
        e.printStackTrace();
    }
}
 
开发者ID:KernelFreeze,项目名称:BedrockProxy,代码行数:19,代码来源:ServerHandshakePacket.java

示例3: initialize

import java.security.spec.ECGenParameterSpec; //导入依赖的package包/类
public void initialize(
    int strength,
    SecureRandom random)
{
    this.random = random;

    if (ecParams != null)
    {
        try
        {
            initialize((ECGenParameterSpec)ecParams, random);
        }
        catch (InvalidAlgorithmParameterException e)
        {
            throw new InvalidParameterException("key size not configurable.");
        }
    }
    else
    {
        throw new InvalidParameterException("unknown key size.");
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:23,代码来源:KeyPairGeneratorSpi.java

示例4: initialize

import java.security.spec.ECGenParameterSpec; //导入依赖的package包/类
public void initialize(
    int             strength,
    SecureRandom    random)
{
    this.strength = strength;
    this.random = random;
    ECGenParameterSpec ecParams = (ECGenParameterSpec)ecParameters.get(Integers.valueOf(strength));

    if (ecParams != null)
    {
        try
        {
            initialize(ecParams, random);
        }
        catch (InvalidAlgorithmParameterException e)
        {
            throw new InvalidParameterException("key size not configurable.");
        }
    }
    else
    {
        throw new InvalidParameterException("unknown key size.");
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:25,代码来源:KeyPairGeneratorSpi.java

示例5: initialize

import java.security.spec.ECGenParameterSpec; //导入依赖的package包/类
public void initialize(
    int strength,
    SecureRandom random)
{
    this.strength = strength;
    this.random = random;

    if (ecParams != null)
    {
        try
        {
            initialize((ECGenParameterSpec)ecParams, random);
        }
        catch (InvalidAlgorithmParameterException e)
        {
            throw new InvalidParameterException("key size not configurable.");
        }
    }
    else
    {
        throw new InvalidParameterException("unknown key size.");
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:24,代码来源:KeyPairGeneratorSpi.java

示例6: getPublicKey

import java.security.spec.ECGenParameterSpec; //导入依赖的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

示例7: getPrivateKey

import java.security.spec.ECGenParameterSpec; //导入依赖的package包/类
/**
 * Returns the ECPrivateKey instance from its raw bytes. Note that you must provide the "s" value of the 
 * private key, not e.g. the byte array from reading a PKCS#8 key file.
 * 
 * @param privateKeyBytes The byte array (the "s" value) of the private key
 * @return The ECPrivateKey instance
 */
public static ECPrivateKey getPrivateKey(byte[] privateKeyBytes) {
	try {
		AlgorithmParameters parameters = AlgorithmParameters.getInstance("EC");
		parameters.init(new ECGenParameterSpec("secp256r1"));
		
		ECParameterSpec ecParameterSpec = parameters.getParameterSpec(ECParameterSpec.class);
		ECPrivateKeySpec ecPrivateKeySpec = new ECPrivateKeySpec(new BigInteger(privateKeyBytes), ecParameterSpec);
		
		ECPrivateKey privateKey = (ECPrivateKey) KeyFactory.getInstance("EC").generatePrivate(ecPrivateKeySpec);

		return privateKey;
	} catch (NoSuchAlgorithmException | InvalidKeySpecException | InvalidParameterSpecException e) {
		getLogger().error(e.getClass().getSimpleName() + " occurred when trying to get private key from raw bytes", e);
		return null;
	}
}
 
开发者ID:V2GClarity,项目名称:RISE-V2G,代码行数:24,代码来源:SecurityUtils.java

示例8: initialize

import java.security.spec.ECGenParameterSpec; //导入依赖的package包/类
@Override
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    if (params instanceof ECParameterSpec) {
        this.params = ECUtil.getECParameterSpec(null,
                                                (ECParameterSpec)params);
        if (this.params == null) {
            throw new InvalidAlgorithmParameterException(
                "Unsupported curve: " + params);
        }
    } else if (params instanceof ECGenParameterSpec) {
        String name = ((ECGenParameterSpec)params).getName();
        this.params = ECUtil.getECParameterSpec(null, name);
        if (this.params == null) {
            throw new InvalidAlgorithmParameterException(
                "Unknown curve name: " + name);
        }
    } else {
        throw new InvalidAlgorithmParameterException(
            "ECParameterSpec or ECGenParameterSpec required for EC");
    }
    this.keySize =
        ((ECParameterSpec)this.params).getCurve().getField().getFieldSize();
    this.random = random;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:ECKeyPairGenerator.java

示例9: getEccCurveNameFromSpec

import java.security.spec.ECGenParameterSpec; //导入依赖的package包/类
@Test
public void getEccCurveNameFromSpec()
    throws InvalidAlgorithmParameterException, NoSuchAlgorithmException {

    /* generate key pair */
    KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC");
    ECGenParameterSpec genSpec = new ECGenParameterSpec("secp256r1");
    kpg.initialize(genSpec);

    KeyPair pair = kpg.genKeyPair();
    ECPrivateKey priv = (ECPrivateKey)pair.getPrivate();

    ECParameterSpec spec = priv.getParams();

    String curveName = Ecc.getCurveName(spec);

    assertEquals(curveName, "SECP256R1");
}
 
开发者ID:wolfSSL,项目名称:wolfcrypt-jni,代码行数:19,代码来源:EccTest.java

示例10: testKeyPairGeneratorEccKeyGenAllCurves

import java.security.spec.ECGenParameterSpec; //导入依赖的package包/类
@Test
public void testKeyPairGeneratorEccKeyGenAllCurves()
    throws NoSuchProviderException, NoSuchAlgorithmException,
           InvalidAlgorithmParameterException {

    /* try generating keys for all supported curves */
    for (int i = 0; i < enabledCurves.size(); i++) {

        KeyPairGenerator kpg =
            KeyPairGenerator.getInstance("EC", "wolfJCE");

        ECGenParameterSpec ecSpec =
            new ECGenParameterSpec(enabledCurves.get(i));
        kpg.initialize(ecSpec);

        KeyPair kp = kpg.generateKeyPair();
    }
}
 
开发者ID:wolfSSL,项目名称:wolfcrypt-jni,代码行数:19,代码来源:WolfCryptKeyPairGeneratorTest.java

示例11: testKeyPairGeneratorEccMultipleInits

import java.security.spec.ECGenParameterSpec; //导入依赖的package包/类
@Test
public void testKeyPairGeneratorEccMultipleInits()
    throws NoSuchProviderException, NoSuchAlgorithmException,
           InvalidAlgorithmParameterException {

    if (enabledCurves.size() > 0) {

        KeyPairGenerator kpg =
            KeyPairGenerator.getInstance("EC", "wolfJCE");

        ECGenParameterSpec ecSpec =
            new ECGenParameterSpec(enabledCurves.get(0));

        kpg.initialize(ecSpec);
        kpg.initialize(ecSpec);
    }
}
 
开发者ID:wolfSSL,项目名称:wolfcrypt-jni,代码行数:18,代码来源:WolfCryptKeyPairGeneratorTest.java

示例12: testKeyPairGeneratorEccMultipleKeyGen

import java.security.spec.ECGenParameterSpec; //导入依赖的package包/类
@Test
public void testKeyPairGeneratorEccMultipleKeyGen()
    throws NoSuchProviderException, NoSuchAlgorithmException,
           InvalidAlgorithmParameterException {

    if (enabledCurves.size() > 0) {

        KeyPairGenerator kpg =
            KeyPairGenerator.getInstance("EC", "wolfJCE");

        ECGenParameterSpec ecSpec =
            new ECGenParameterSpec(enabledCurves.get(0));
        kpg.initialize(ecSpec);

        KeyPair kp1 = kpg.generateKeyPair();
        KeyPair kp2 = kpg.generateKeyPair();
    }
}
 
开发者ID:wolfSSL,项目名称:wolfcrypt-jni,代码行数:19,代码来源:WolfCryptKeyPairGeneratorTest.java

示例13: testKeyPairGeneratorEccNewKeyFromExisting

import java.security.spec.ECGenParameterSpec; //导入依赖的package包/类
@Test
public void testKeyPairGeneratorEccNewKeyFromExisting()
    throws NoSuchProviderException, NoSuchAlgorithmException,
           InvalidAlgorithmParameterException, InvalidKeySpecException {

    if (enabledCurves.size() > 0) {

        KeyPairGenerator kpg =
            KeyPairGenerator.getInstance("EC", "wolfJCE");

        ECGenParameterSpec ecSpec =
            new ECGenParameterSpec(enabledCurves.get(0));
        kpg.initialize(ecSpec);

        KeyPair kp = kpg.generateKeyPair();

        KeyFactory kf = KeyFactory.getInstance("EC");
        PublicKey pub = kf.generatePublic(new X509EncodedKeySpec(
                    kp.getPublic().getEncoded()));
        PrivateKey priv = kf.generatePrivate(new PKCS8EncodedKeySpec(
                    kp.getPrivate().getEncoded()));
    }
}
 
开发者ID:wolfSSL,项目名称:wolfcrypt-jni,代码行数:24,代码来源:WolfCryptKeyPairGeneratorTest.java

示例14: isAvailableCurve

import java.security.spec.ECGenParameterSpec; //导入依赖的package包/类
private static boolean isAvailableCurve(int curveId) {
    String oid = idToOidMap.get(curveId);
    if (oid != null) {
        AlgorithmParameters params = null;
        try {
            params = JsseJce.getAlgorithmParameters("EC");
            params.init(new ECGenParameterSpec(oid));
        } catch (Exception e) {
            return false;
        }

        // cache the parameters
        idToParams.put(curveId, params);

        return true;
    }

    return false;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:SupportedEllipticCurvesExtension.java

示例15: generateEcKeyPair

import java.security.spec.ECGenParameterSpec; //导入依赖的package包/类
@Override
public KeyPair generateEcKeyPair(final EcCurve curveName) throws NoSuchAlgorithmException,
                                                                 InvalidAlgorithmParameterException {
	if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
		Security.addProvider(new BouncyCastleProvider());
	}
	KeyPairGenerator kpg;
	try {
		kpg = KeyPairGenerator.getInstance("EC", BouncyCastleProvider.PROVIDER_NAME); //$NON-NLS-1$
	}
	catch (final Exception e) {
		Logger.getLogger("es.gob.jmulticard").warning( //$NON-NLS-1$
			"No se ha podido obtener un generador de pares de claves de curva eliptica con SpongyCastle, se usara el generador por defecto: " + e //$NON-NLS-1$
		);
		kpg = KeyPairGenerator.getInstance("EC"); //$NON-NLS-1$
	}

	Logger.getLogger("es.gob.jmulticard").info( //$NON-NLS-1$
		"Seleccionado el siguiente generador de claves de curva eliptica: " + kpg.getClass().getName() //$NON-NLS-1$
	);

	final AlgorithmParameterSpec parameterSpec = new ECGenParameterSpec(curveName.toString());
	kpg.initialize(parameterSpec);
	return kpg.generateKeyPair();
}
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:26,代码来源:JseCryptoHelper.java


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