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


Java ECNamedCurveSpec类代码示例

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


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

示例1: convertSpec

import org.bouncycastle.jce.spec.ECNamedCurveSpec; //导入依赖的package包/类
public static ECParameterSpec convertSpec(
    EllipticCurve ellipticCurve,
    org.bouncycastle.jce.spec.ECParameterSpec spec)
{
    if (spec instanceof ECNamedCurveParameterSpec)
    {
        return new ECNamedCurveSpec(
            ((ECNamedCurveParameterSpec)spec).getName(),
            ellipticCurve,
            new ECPoint(
                spec.getG().getX().toBigInteger(),
                spec.getG().getY().toBigInteger()),
            spec.getN(),
            spec.getH());
    }
    else
    {
        return new ECParameterSpec(
            ellipticCurve,
            new ECPoint(
                spec.getG().getX().toBigInteger(),
                spec.getG().getY().toBigInteger()),
            spec.getN(),
            spec.getH().intValue());
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:27,代码来源:EC5Util.java

示例2: getPubKeyFromCurve

import org.bouncycastle.jce.spec.ECNamedCurveSpec; //导入依赖的package包/类
/**
 * Decode based on X, Y 32 byte integers
 * 
 * @param pubKey
 * @param curveName
 *            - Example secp256r1
 * @return
 * @throws InvalidKeySpecException
 * @throws NoSuchAlgorithmException
 * @throws NoSuchProviderException
 */
public static PublicKey getPubKeyFromCurve(byte[] pubKey, String curveName)
		throws InvalidKeySpecException, NoSuchAlgorithmException,
		NoSuchProviderException {

	ECNamedCurveParameterSpec spec = ECNamedCurveTable
			.getParameterSpec(curveName);
	KeyFactory kf = KeyFactory.getInstance("ECDSA",
			new BouncyCastleProvider());
	ECNamedCurveSpec params = new ECNamedCurveSpec(curveName,
			spec.getCurve(), spec.getG(), spec.getN());
	ECPoint point = ECPointUtil.decodePoint(params.getCurve(), pubKey);
	ECPublicKeySpec pubKeySpec = new ECPublicKeySpec(point, params);
	ECPublicKey pk = (ECPublicKey) kf.generatePublic(pubKeySpec);
	return pk;
}
 
开发者ID:zsavvas,项目名称:ReCRED_FIDO_UAF_OIDC,代码行数:27,代码来源:KeyCodec.java

示例3: convertSpec

import org.bouncycastle.jce.spec.ECNamedCurveSpec; //导入依赖的package包/类
public static ECParameterSpec convertSpec(
    EllipticCurve ellipticCurve,
    org.bouncycastle.jce.spec.ECParameterSpec spec)
{
    if (spec instanceof ECNamedCurveParameterSpec)
    {
        return new ECNamedCurveSpec(
            ((ECNamedCurveParameterSpec)spec).getName(),
            ellipticCurve,
            new ECPoint(
                spec.getG().getAffineXCoord().toBigInteger(),
                spec.getG().getAffineYCoord().toBigInteger()),
            spec.getN(),
            spec.getH());
    }
    else
    {
        return new ECParameterSpec(
            ellipticCurve,
            new ECPoint(
                spec.getG().getAffineXCoord().toBigInteger(),
                spec.getG().getAffineYCoord().toBigInteger()),
            spec.getN(),
            spec.getH().intValue());
    }
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:27,代码来源:EC5Util.java

示例4: getNamedCurve

import org.bouncycastle.jce.spec.ECNamedCurveSpec; //导入依赖的package包/类
/**
 * Determines the name of the domain parameters that were used for generating the key.
 *
 * @param key An EC key
 * @return The name of the domain parameters that were used for the EC key,
 *         or an empty string if curve is unknown.
 */
public static String getNamedCurve(Key key) {

	if (!(key instanceof ECKey)) {
		throw new InvalidParameterException("Not a EC private key.");
	}

	ECKey ecKey = (ECKey) key;
	ECParameterSpec params = ecKey.getParams();
	if (!(params instanceof ECNamedCurveSpec)) {
		return "";
	}

	ECNamedCurveSpec ecPrivateKeySpec = (ECNamedCurveSpec) params;
	String namedCurve = ecPrivateKeySpec.getName();
	return namedCurve;
}
 
开发者ID:kaikramer,项目名称:keystore-explorer,代码行数:24,代码来源:EccUtil.java

示例5: toJcaPrivateKey

import org.bouncycastle.jce.spec.ECNamedCurveSpec; //导入依赖的package包/类
private static ECPrivateKey toJcaPrivateKey(org.bouncycastle.asn1.sec.ECPrivateKey ecPrivateKey)
        throws GeneralSecurityException {
    String curveName = null;
    ASN1ObjectIdentifier curveId = (ASN1ObjectIdentifier) ecPrivateKey.getParameters();
    if (curveId.equals(secp224r1_OID)) {
        curveName = "secp224r1";
    } else if (curveId.equals(prime256v1_OID)) {
        curveName = "prime256v1";
    } else if (curveId.equals(secp384r1_OID)) {
        curveName = "secp384r1";
    } else if (curveId.equals(secp521r1_OID)) {
        curveName = "secp521r1";
    } else {
        throw new IllegalStateException("Unknown curve OID: " + curveId);
    }

    ECNamedCurveParameterSpec sp = ECNamedCurveTable.getParameterSpec(curveName);
    ECParameterSpec params = new ECNamedCurveSpec(sp.getName(), sp.getCurve(), sp.getG(),
            sp.getN(), sp.getH());

    ECPrivateKeySpec pkSpec = new ECPrivateKeySpec(ecPrivateKey.getKey(), params);
    KeyFactory kf = KeyFactory.getInstance("EC");
    ECPrivateKey privateKey = (ECPrivateKey) kf.generatePrivate(pkSpec);

    return privateKey;
}
 
开发者ID:nelenkov,项目名称:keystore-decryptor,代码行数:27,代码来源:SoftKeymasterBlob.java

示例6: getECPublicKey

import org.bouncycastle.jce.spec.ECNamedCurveSpec; //导入依赖的package包/类
public static PublicKey getECPublicKey(java.security.spec.ECPoint w, String stdCurveName) throws NoSuchAlgorithmException, InvalidKeySpecException {
  ECNamedCurveParameterSpec parameterSpec = ECNamedCurveTable.getParameterSpec(stdCurveName);
  java.security.spec.ECParameterSpec params = new ECNamedCurveSpec(parameterSpec.getName(), parameterSpec.getCurve(),
          parameterSpec.getG(), parameterSpec.getN(), parameterSpec.getH(), parameterSpec.getSeed());
  KeySpec keySpec = new java.security.spec.ECPublicKeySpec(w, params);
  KeyFactory keyFactory = KeyFactory.getInstance("EC");
  return keyFactory.generatePublic(keySpec);
}
 
开发者ID:google,项目名称:webauthndemo,代码行数:9,代码来源:Crypto.java

示例7: getPrivKeyFromCurve

import org.bouncycastle.jce.spec.ECNamedCurveSpec; //导入依赖的package包/类
/**
 * Decode based on d - 32 byte integer
 * 
 * @param privKey
 * @param curveName
 *            - Example secp256r1
 * @return
 * @throws InvalidKeySpecException
 * @throws NoSuchAlgorithmException
 * @throws NoSuchProviderException
 */
public static PrivateKey getPrivKeyFromCurve(byte[] privKey,
		String curveName) throws InvalidKeySpecException,
		NoSuchAlgorithmException, NoSuchProviderException {

	ECNamedCurveParameterSpec spec = ECNamedCurveTable
			.getParameterSpec(curveName);
	KeyFactory kf = KeyFactory.getInstance("ECDSA",
			new BouncyCastleProvider());
	ECNamedCurveSpec params = new ECNamedCurveSpec(curveName,
			spec.getCurve(), spec.getG(), spec.getN());
	ECPrivateKeySpec priKey = new ECPrivateKeySpec(new BigInteger(privKey), // d
			params);
	return kf.generatePrivate(priKey);
}
 
开发者ID:zsavvas,项目名称:ReCRED_FIDO_UAF_OIDC,代码行数:26,代码来源:KeyCodec.java

示例8: EllipticCurveKeyUtil

import org.bouncycastle.jce.spec.ECNamedCurveSpec; //导入依赖的package包/类
public EllipticCurveKeyUtil()
    throws NoSuchProviderException, NoSuchAlgorithmException, InvalidAlgorithmParameterException {
  Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

  _keyFactory = KeyFactory.getInstance(CRYPTO_TYPE_ECDH, PROVIDER_BOUNCY_CASTLE);
  _ecNamedCurveParameterSpec = ECNamedCurveTable.getParameterSpec(Constants.SECP256R1); // P256 curve
  _ecNamedCurveSpec = new ECNamedCurveSpec(Constants.SECP256R1, _ecNamedCurveParameterSpec.getCurve(), _ecNamedCurveParameterSpec
      .getG(), _ecNamedCurveParameterSpec.getN());

  _ecParameterSpec = ECNamedCurveTable.getParameterSpec(Constants.SECP256R1); // P256 curve
  _keyPairGenerator = KeyPairGenerator.getInstance(CRYPTO_TYPE_ECDH, PROVIDER_BOUNCY_CASTLE);
  _keyPairGenerator.initialize(_ecParameterSpec, new SecureRandom());
}
 
开发者ID:gauntface,项目名称:web-push-java,代码行数:14,代码来源:EllipticCurveKeyUtil.java

示例9: getPublicKeyFromBytes

import org.bouncycastle.jce.spec.ECNamedCurveSpec; //导入依赖的package包/类
private PublicKey getPublicKeyFromBytes(byte[] pubKey) throws NoSuchAlgorithmException, InvalidKeySpecException {
    ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec("secp384r1");
    KeyFactory keyFactory = KeyFactory.getInstance("ECDH", new BouncyCastleProvider());

    ECNamedCurveSpec params = new ECNamedCurveSpec("secp384r1", spec.getCurve(), spec.getG(), spec.getN());
    ECPoint point =  ECPointUtil.decodePoint(params.getCurve(), pubKey);
    ECPublicKeySpec pubKeySpec = new ECPublicKeySpec(point, params);
    ECPublicKey ecPublicKey = (ECPublicKey) keyFactory.generatePublic(pubKeySpec);
    return ecPublicKey;
}
 
开发者ID:iotauth,项目名称:iotauth,代码行数:11,代码来源:DistributionDiffieHellman.java

示例10: createNamedCurveSpec

import org.bouncycastle.jce.spec.ECNamedCurveSpec; //导入依赖的package包/类
protected ECNamedCurveSpec createNamedCurveSpec(String curveName)
    throws InvalidAlgorithmParameterException
{
    // NOTE: Don't bother with custom curves here as the curve will be converted to JCE type shortly

    X9ECParameters p = ECUtils.getDomainParametersFromName(curveName);
    if (p == null)
    {
        try
        {
            // Check whether it's actually an OID string (SunJSSE ServerHandshaker setupEphemeralECDHKeys bug)
            p = ECNamedCurveTable.getByOID(new ASN1ObjectIdentifier(curveName));
            if (p == null)
            {
                throw new InvalidAlgorithmParameterException("unknown curve OID: " + curveName);
            }
        }
        catch (IllegalArgumentException ex)
        {
            throw new InvalidAlgorithmParameterException("unknown curve name: " + curveName);
        }
    }

    // Work-around for JDK bug -- it won't look up named curves properly if seed is present
    byte[] seed = null; //p.getSeed();

    return new ECNamedCurveSpec(curveName, p.getCurve(), p.getG(), p.getN(), p.getH(), seed);
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:29,代码来源:KeyPairGeneratorSpi.java

示例11: initializeNamedCurve

import org.bouncycastle.jce.spec.ECNamedCurveSpec; //导入依赖的package包/类
protected void initializeNamedCurve(String curveName, SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    ECNamedCurveSpec namedCurve = createNamedCurveSpec(curveName);
    this.ecParams = namedCurve;
    this.param = createKeyGenParamsJCE(namedCurve, random);
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:8,代码来源:KeyPairGeneratorSpi.java

示例12: showJcaPrivateKey

import org.bouncycastle.jce.spec.ECNamedCurveSpec; //导入依赖的package包/类
private static void showJcaPrivateKey(PrivateKey pk) throws Exception {
    if (pk instanceof RSAPrivateKey) {
        RSAPrivateKey rsaPrivKey = (RSAPrivateKey) pk;
        PemObject rsaPem = new PemObject("RSA PRIVATE KEY", rsaPrivKey.getEncoded());
        StringWriter sw = new StringWriter();
        PemWriter pemWriter = new PemWriter(sw);
        try {
            pemWriter.writeObject(rsaPem);
        } finally {
            pemWriter.close();
        }
        System.out.println(sw.toString());
    } else if (pk instanceof java.security.interfaces.ECPrivateKey) {
        java.security.interfaces.ECPrivateKey ecPrivKey = (java.security.interfaces.ECPrivateKey) pk;
        System.out.printf("EC S: %s... (%d)\n",
                ecPrivKey.getS().toString(16).substring(0, 32),
                ecPrivKey.getS().bitLength());
        if (ecPrivKey.getParams() instanceof ECNamedCurveSpec) {
            ECNamedCurveSpec namedCurveSpec = (ECNamedCurveSpec) ecPrivKey.getParams();
            System.out.println("curve name: " + namedCurveSpec.getName());
        } else {
            System.out.println("EC params: " + ecPrivKey.getParams());
        }
    } else if (pk instanceof DSAPrivateKey) {
        DSAPrivateKey dsaPrivKey = (DSAPrivateKey) pk;
        System.out.printf("DSA X: %s... (%d)\n",
                dsaPrivKey.getX().toString(16).substring(0, 32), dsaPrivKey.getX()
                        .bitLength());
        System.out.println("DSA params: " + dsaPrivKey.getParams());
    } else {
        System.out.println("Unknown private key type: " + pk.getClass().getName());
    }
}
 
开发者ID:nelenkov,项目名称:keystore-decryptor,代码行数:34,代码来源:Main.java

示例13: convertX9Parameters

import org.bouncycastle.jce.spec.ECNamedCurveSpec; //导入依赖的package包/类
private ECParameterSpec convertX9Parameters(ASN1ObjectIdentifier curveOid, X9ECParameters curveParameters)
{
    return new ECNamedCurveSpec(curveOid.getId(),
                                curveParameters.getCurve(),
                                curveParameters.getG(),
                                curveParameters.getN(),
                                curveParameters.getH(),
                                curveParameters.getSeed());
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:10,代码来源:JcaPGPKeyConverter.java

示例14: ECDH_ECDSA

import org.bouncycastle.jce.spec.ECNamedCurveSpec; //导入依赖的package包/类
/**
 * 
 * @param curveName
 * @param keyLengthBytes Length of a byte array encoding of one (public or private) key
 * @throws NoSuchAlgorithmException
 * @throws InvalidAlgorithmParameterException
 */
ECDH_ECDSA(String curveName, int keyLengthBytes) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    X9ECParameters params = NISTNamedCurves.getByName(curveName);
    ecParameterSpec = new ECNamedCurveSpec(curveName, params.getCurve(), params.getG(), params.getN(), params.getH(), null);
    this.keyLengthBytes = keyLengthBytes;
    
    encryptionKeyPairGenerator = new KeyPairGenerator.ECDH();
    encryptionKeyPairGenerator.initialize(ecParameterSpec);
    
    signingKeyPairGenerator = new KeyPairGenerator.ECDSA();
    signingKeyPairGenerator.initialize(ecParameterSpec);
    
    ecdhKeyFactory = new BouncyECDHKeyFactory();
    ecdsaKeyFactory = new BouncyECDSAKeyFactory();
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:22,代码来源:ECDH_ECDSA.java

示例15: eciesDecrypt

import org.bouncycastle.jce.spec.ECNamedCurveSpec; //导入依赖的package包/类
public ByteString eciesDecrypt(PrivateKey recipientPrivateKey, ByteString cipherText) {
    BCECPrivateKey bcecPrivateKey = (BCECPrivateKey) recipientPrivateKey;
    ECNamedCurveSpec ecNamedCurveSpec = (ECNamedCurveSpec) bcecPrivateKey.getParams();
    int level = SecurityLevel.from(ecNamedCurveSpec.getName()).size();

    //cipherText = ephemeralPubKeyBytes + encryptedTokBytes + macBytes
    //ephemeralPubKeyBytes = first ((384+7)/8)*2 + 1 bytes = first 97 bytes
    //hmac is sha3_384 = 48 bytes or sha3_256 = 32 bytes
    int ephemeralPubKeyLength = ((level + 7) / 8) * 2 + 1;
    int hmacLength = level >> 3;
    int cipherTextLength = cipherText.size();

    if (cipherTextLength <= ephemeralPubKeyLength + hmacLength)
        throw new RuntimeException(String.format("Illegal cipherText length: %d must be > %d", cipherTextLength, ephemeralPubKeyLength + hmacLength));

    ByteString ephemeralPubKey = cipherText.substring(0, ephemeralPubKeyLength);
    ByteString encryptedContent = cipherText.substring(ephemeralPubKeyLength, cipherTextLength - hmacLength);
    ByteString hmac = cipherText.substring(cipherTextLength - hmacLength);

    ECPrivateKeyParameters ecdhPrivateKeyParameters;
    try {
        ecdhPrivateKeyParameters = (ECPrivateKeyParameters) (PrivateKeyFactory.createKey(bcecPrivateKey.getEncoded()));
    } catch (IOException e) {
        logger.error("ECIES decrypt load private key exception", e);
        throw new RuntimeException(e);
    }
    ECDomainParameters ecDomainParameters = ecdhPrivateKeyParameters.getParameters();
    ECCurve ecCurve = ecDomainParameters.getCurve();
    ECPublicKeyParameters ecPublicKeyParameters = new ECPublicKeyParameters(ecCurve.decodePoint(ephemeralPubKey.toByteArray()), ecDomainParameters);
    BasicAgreement agree = new ECDHBasicAgreement();
    agree.init(ecdhPrivateKeyParameters);
    byte[] keyAgreement = agree.calculateAgreement(ecPublicKeyParameters).toByteArray();

    HKDFParameters hkdfParameters = new HKDFParameters(keyAgreement, null, null);
    HKDFBytesGenerator hkdfBytesGenerator = new HKDFBytesGenerator(digest);
    hkdfBytesGenerator.init(hkdfParameters);
    byte[] hkdfOutputBytes = new byte[AESKEY_LENGTH + HMACKEY_LENGTH];
    hkdfBytesGenerator.generateBytes(hkdfOutputBytes, 0, AESKEY_LENGTH + HMACKEY_LENGTH);
    ByteString hkdfOutput = ByteString.copyFrom(hkdfOutputBytes);
    ByteString aesKey = hkdfOutput.substring(0, AESKEY_LENGTH);
    ByteString hmacKey = hkdfOutput.substring(AESKEY_LENGTH, AESKEY_LENGTH + HMACKEY_LENGTH);
    HMac hMac = new HMac(digest);
    hMac.init(new KeyParameter(hmacKey.toByteArray()));
    hMac.update(encryptedContent.toByteArray(), 0, encryptedContent.size());
    byte[] recoveredHmac = new byte[hMac.getMacSize()];
    hMac.doFinal(recoveredHmac, 0);
    if (!MessageDigest.isEqual(hmac.toByteArray(), recoveredHmac)) {
        throw new RuntimeException("HMAC verify failed");
    }

    CFBBlockCipher aesCipher = new CFBBlockCipher(
            new AESEngine(), BLOCK_BIT_SIZE);
    ByteString iv = encryptedContent.substring(0, IV_LENGTH);
    CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(aesKey.toByteArray()), iv.toByteArray());
    aesCipher.init(false, ivAndKey);
    byte[] decryptedBytes = new byte[500];
    aesCipher.decryptBlock(encryptedContent.substring(IV_LENGTH).toByteArray(), 0, decryptedBytes, 0);
    return ByteString.copyFrom(decryptedBytes);
}
 
开发者ID:GrapeBaBa,项目名称:fabric-java,代码行数:60,代码来源:Crypto.java


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