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


Java ECParameterSpec类代码示例

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


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

示例1: register

import org.bouncycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
public RawRegisterResponse register(RegisterRequest registerRequest) throws Exception {

        byte[] applicationSha256 = registerRequest.getApplicationSha256();
        byte[] challengeSha256 = registerRequest.getChallengeSha256();

        // generate ECC key
        SecureRandom random = new SecureRandom();
        ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("secp256r1");
        KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA");
        g.initialize(ecSpec, random);
        KeyPair keyPair = g.generateKeyPair();

        byte[] keyHandle = new byte[64];
        random.nextBytes(keyHandle);
        dataStore.put(new String(keyHandle), keyPair);

        byte[] userPublicKey = stripMetaData(keyPair.getPublic().getEncoded());

        byte[] signedData = RawRegisterResponse.packBytesToSign(applicationSha256, challengeSha256,
                keyHandle, userPublicKey);

        byte[] signature = sign(signedData, certificatePrivateKey);

        return new RawRegisterResponse(userPublicKey, keyHandle, attestationCertificate, signature);
    }
 
开发者ID:Yubico,项目名称:java-u2flib-server,代码行数:26,代码来源:SoftKey.java

示例2: getParams

import org.bouncycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
private ECParameterSpec getParams(ECDSAPublicKey key)
{
    if (!key.hasParameters())
    {
        throw new IllegalArgumentException("Public key does not contains EC Params");
    }

    BigInteger p = key.getPrimeModulusP();
    ECCurve.Fp curve = new ECCurve.Fp(p, key.getFirstCoefA(), key.getSecondCoefB());

    ECPoint G = curve.decodePoint(key.getBasePointG());

    BigInteger order = key.getOrderOfBasePointR();
    BigInteger coFactor = key.getCofactorF();
               // TODO: update to use JDK 1.5 EC API
    ECParameterSpec ecspec = new ECParameterSpec(curve, G, order, coFactor);

    return ecspec;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:20,代码来源:JcaPublicKeyConverter.java

示例3: JCEECPrivateKey

import org.bouncycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
JCEECPrivateKey(
    String                  algorithm,
    ECPrivateKeyParameters  params,
    ECParameterSpec         spec)
{
    ECDomainParameters      dp = params.getParameters();

    this.algorithm = algorithm;
    this.d = params.getD();

    if (spec == null)
    {
        this.ecSpec = new ECParameterSpec(
                        dp.getCurve(),
                        dp.getG(),
                        dp.getN(),
                        dp.getH(),
                        dp.getSeed());
    }
    else
    {
        this.ecSpec = spec;
    }
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:25,代码来源:JCEECPrivateKey.java

示例4: generatePublicKeyParameter

import org.bouncycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
static public AsymmetricKeyParameter generatePublicKeyParameter(
    PublicKey    key)
    throws InvalidKeyException
{
    if (key instanceof ECPublicKey)
    {
        ECPublicKey    k = (ECPublicKey)key;
        ECParameterSpec s = k.getParams();

        return new ECPublicKeyParameters(
                        k.getQ(),
                        new ECDomainParameters(s.getCurve(), s.getG(), s.getN()));
    }

    throw new InvalidKeyException("can't identify EC public key.");
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:17,代码来源:ECUtil.java

示例5: generatePrivateKeyParameter

import org.bouncycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
static public AsymmetricKeyParameter generatePrivateKeyParameter(
    PrivateKey    key)
    throws InvalidKeyException
{
    if (key instanceof ECPrivateKey)
    {
        ECPrivateKey    k = (ECPrivateKey)key;
        ECParameterSpec s = k.getParams();

        return new ECPrivateKeyParameters(
                        k.getD(),
                        new ECDomainParameters(s.getCurve(), s.getG(), s.getN()));
    }
                    
    throw new InvalidKeyException("can't identify EC private key.");
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:17,代码来源:ECUtil.java

示例6: initialize

import org.bouncycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
public void initialize(
    int             strength,
    SecureRandom    random)
{
    this.strength = strength;
    this.random = random;
    this.ecParams = (ECParameterSpec)ecParameters.get(new Integer(strength));

    if (ecParams != null)
    {
        param = new ECKeyGenerationParameters(new ECDomainParameters(ecParams.getCurve(), ecParams.getG(), ecParams.getN()), random);

        engine.init(param);
        initialised = true;
    }
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:17,代码来源:JDKKeyPairGenerator.java

示例7: JCEECPublicKey

import org.bouncycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
JCEECPublicKey(
    String                  algorithm,
    ECPublicKeyParameters   params,
    ECParameterSpec         spec)
{
    ECDomainParameters      dp = params.getParameters();

    this.algorithm = algorithm;
    this.q = params.getQ();

    if (spec == null)
    {
        this.ecSpec = new ECParameterSpec(
                        dp.getCurve(),
                        dp.getG(),
                        dp.getN(),
                        dp.getH(),
                        dp.getSeed());
    }
    else
    {
        this.ecSpec = spec;
    }
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:25,代码来源:JCEECPublicKey.java

示例8: testExportImport

import org.bouncycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
@Test
public void testExportImport() throws GeneralSecurityException {

	// Create a curve25519 parameter spec
	X9ECParameters params = CustomNamedCurves.getByName("curve25519");
	ECParameterSpec ecParameterSpec = new ECParameterSpec(params.getCurve(), params.getG(), params.getN(), params.getH(), params.getSeed());

	// Create public key
	KeyAgreementPeer peer = new ECDHPeer(ecParameterSpec, null, "BC");
	ECPublicKey ecPublicKey = (ECPublicKey) peer.getPublicKey();

	// Export public key
	byte[] encoded = ecPublicKey.getQ().getEncoded(true);

	System.out.println(Arrays.toString(encoded));
	System.out.println("Encoded length: " + encoded.length);

	// Import public key
	ECPublicKey importedECPublicKey = loadPublicKey(encoded);

	Assert.assertArrayEquals(ecPublicKey.getEncoded(), importedECPublicKey.getEncoded());
}
 
开发者ID:martinwithaar,项目名称:Encryptor4j,代码行数:23,代码来源:ECDHExportTest.java

示例9: loadPrivateKey

import org.bouncycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
/**
 * Load the private key from a URL-safe base64 encoded string
 *
 * @param encodedPrivateKey
 * @return
 * @throws NoSuchProviderException
 * @throws NoSuchAlgorithmException
 * @throws InvalidKeySpecException
 */
public static PrivateKey loadPrivateKey(String encodedPrivateKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException {
    byte[] decodedPrivateKey = base64Decode(encodedPrivateKey);

    // prime256v1 is NIST P-256
    ECParameterSpec params = ECNamedCurveTable.getParameterSpec("prime256v1");
    ECPrivateKeySpec prvkey = new ECPrivateKeySpec(new BigInteger(decodedPrivateKey), params);
    KeyFactory kf = KeyFactory.getInstance("ECDH", BouncyCastleProvider.PROVIDER_NAME);

    return kf.generatePrivate(prvkey);
}
 
开发者ID:web-push-libs,项目名称:webpush-java,代码行数:20,代码来源:Utils.java

示例10: getOrderBitLength

import org.bouncycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
public static int getOrderBitLength(BigInteger order, BigInteger privateValue)
{
    if (order == null)     // implicitly CA
    {
        ECParameterSpec implicitCA = BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa();

        if (implicitCA == null)
        {
            return privateValue.bitLength();   // a guess but better than an exception!
        }

        return implicitCA.getN().bitLength();
    }
    else
    {
        return order.bitLength();
    }
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:19,代码来源:ECUtil.java

示例11: getNamedCurveOid

import org.bouncycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
public static ASN1ObjectIdentifier getNamedCurveOid(
    ECParameterSpec ecParameterSpec)
{
    for (Enumeration names = ECNamedCurveTable.getNames(); names.hasMoreElements();)
    {
        String name = (String)names.nextElement();

        X9ECParameters params = ECNamedCurveTable.getByName(name);

        if (params.getN().equals(ecParameterSpec.getN())
            && params.getH().equals(ecParameterSpec.getH())
            && params.getCurve().equals(ecParameterSpec.getCurve())
            && params.getG().equals(ecParameterSpec.getG()))
        {
            return org.bouncycastle.asn1.x9.ECNamedCurveTable.getOID(name);
        }
    }

    return null;
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:21,代码来源:ECUtil.java

示例12: DomainParameter

import org.bouncycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
/**
 * Extrahiert aus dem AlogorithmIdentifier die Parameter für DH oder ECDH.
 * Es werden standardisierte DomainParameter und explizite DP erkannt.
 * @param algorithm OID
 */
public DomainParameter(AlgorithmIdentifier aid) {
	if (aid.getAlgorithm().toString().equals(BSIObjectIdentifiers.standardizedDomainParameters.toString())) {
		int dpref = ((ASN1Integer)aid.getParameters()).getPositiveValue().intValue(); 
		getParameters(dpref);	
	} 
	
	else if (aid.getAlgorithm().toString().equals("1.2.840.10045.2.1")) {
		X9ECParameters x9ecp = X9ECParameters.getInstance(aid.getParameters());
		ecSpec = new ECParameterSpec(x9ecp.getCurve(), x9ecp.getG(), x9ecp.getN());
	} 
	
	//TODO properitäre DH Domain Parameter
	
	else throw new UnsupportedOperationException("unsupported Domain Parameters. Algorithm OID: "+aid.getAlgorithm().toString());
}
 
开发者ID:tsenger,项目名称:animamea,代码行数:21,代码来源:DomainParameter.java

示例13: TerminalAuthenticationECDSA

import org.bouncycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
/**
 * @param caDomainParameter
 * @param ecParams
 * @param privateKey
 */
public TerminalAuthenticationECDSA(DomainParameter caDomainParameter, AmECPublicKey taPublicKey, BigInteger taSecretKey) {
	
	super(caDomainParameter);
	
	ECCurve.Fp curve = (Fp) taPublicKey.getParameters().getCurve();
	ECPoint pointG = taPublicKey.getParameters().getG();
	ecp = new ECParameterSpec(curve, pointG, taPublicKey.getParameters().getN());
	
	if (taPublicKey.getOID().toString().equals(BSIObjectIdentifiers.id_TA_ECDSA_SHA_1.toString())) {
		signingAlgorithm = "SHA1withECDSA";
	} else if (taPublicKey.getOID().toString().equals(BSIObjectIdentifiers.id_TA_ECDSA_SHA_224.toString())) {
		signingAlgorithm = "SHA224withECDSA";
	} else if (taPublicKey.getOID().toString().equals(BSIObjectIdentifiers.id_TA_ECDSA_SHA_256.toString())) {
		signingAlgorithm = "SHA256withECDSA";
	} else if (taPublicKey.getOID().toString().equals(BSIObjectIdentifiers.id_TA_ECDSA_SHA_384.toString())) {
		signingAlgorithm = "SHA384withECDSA";
	} else if (taPublicKey.getOID().toString().equals(BSIObjectIdentifiers.id_TA_ECDSA_SHA_512.toString())) {
		signingAlgorithm = "SHA512withECDSA";
	}
	
	this.terminalSK = taSecretKey;
}
 
开发者ID:tsenger,项目名称:animamea,代码行数:28,代码来源:TerminalAuthenticationECDSA.java

示例14: decodePublicKey

import org.bouncycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
/**
 * 
 * @param encodedPublicKey This is the (uncompressed) x,y-representation of a curve point on the P-256 NIST elliptic curve.
 * @return
 */
public static PublicKey decodePublicKey(byte[] encodedPublicKey) {
	PublicKey result = null;
	
	try {
		
		X9ECParameters curve = SECNamedCurves.getByName("secp256r1");
		ECPoint point = curve.getCurve().decodePoint(encodedPublicKey);
		
		result = KeyFactory.getInstance("ECDSA",new BouncyCastleProvider()).generatePublic(new ECPublicKeySpec(point, new ECParameterSpec(curve.getCurve(), curve.getG(), curve.getN(), curve.getH())));
		
	} catch (InvalidKeySpecException | NoSuchAlgorithmException e) {
			e.printStackTrace();
	}
	
	return result;
}
 
开发者ID:arietimmerman,项目名称:OpenAM-U2F,代码行数:22,代码来源:CryptoHelper.java

示例15: isSignatureValid

import org.bouncycastle.jce.spec.ECParameterSpec; //导入依赖的package包/类
@Override
public boolean isSignatureValid(byte[] data, byte[] signature, Pubkey pubkey) {
    try {
        ECParameterSpec spec = new ECParameterSpec(
            EC_CURVE_PARAMETERS.getCurve(),
            EC_CURVE_PARAMETERS.getG(),
            EC_CURVE_PARAMETERS.getN(),
            EC_CURVE_PARAMETERS.getH(),
            EC_CURVE_PARAMETERS.getSeed()
        );

        ECPoint Q = keyToPoint(pubkey.getSigningKey());
        KeySpec keySpec = new ECPublicKeySpec(Q, spec);
        PublicKey publicKey = KeyFactory.getInstance(ALGORITHM_ECDSA, provider).generatePublic(keySpec);

        Signature sig = Signature.getInstance(ALGORITHM_ECDSA, provider);
        sig.initVerify(publicKey);
        sig.update(data);
        return sig.verify(signature);
    } catch (GeneralSecurityException e) {
        throw new ApplicationException(e);
    }
}
 
开发者ID:Dissem,项目名称:Jabit,代码行数:24,代码来源:BouncyCryptography.java


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