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


Java ECPrivateKeySpec类代码示例

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


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

示例1: JCEECPrivateKey

import java.security.spec.ECPrivateKeySpec; //导入依赖的package包/类
public JCEECPrivateKey(
    String              algorithm,
    org.bouncycastle.jce.spec.ECPrivateKeySpec     spec)
{
    this.algorithm = algorithm;
    this.d = spec.getD();

    if (spec.getParams() != null) // can be null if implicitlyCA
    {
        ECCurve curve = spec.getParams().getCurve();
        EllipticCurve ellipticCurve;

        ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed());

        this.ecSpec = EC5Util.convertSpec(ellipticCurve, spec.getParams());
    }
    else
    {
        this.ecSpec = null;
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:22,代码来源:JCEECPrivateKey.java

示例2: BCDSTU4145PrivateKey

import java.security.spec.ECPrivateKeySpec; //导入依赖的package包/类
public BCDSTU4145PrivateKey(
    org.bouncycastle.jce.spec.ECPrivateKeySpec spec)
{
    this.d = spec.getD();

    if (spec.getParams() != null) // can be null if implicitlyCA
    {
        ECCurve curve = spec.getParams().getCurve();
        EllipticCurve ellipticCurve;

        ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed());

        this.ecSpec = EC5Util.convertSpec(ellipticCurve, spec.getParams());
    }
    else
    {
        this.ecSpec = null;
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:20,代码来源:BCDSTU4145PrivateKey.java

示例3: BCECPrivateKey

import java.security.spec.ECPrivateKeySpec; //导入依赖的package包/类
public BCECPrivateKey(
    String algorithm,
    org.bouncycastle.jce.spec.ECPrivateKeySpec spec,
    ProviderConfiguration configuration)
{
    this.algorithm = algorithm;
    this.d = spec.getD();

    if (spec.getParams() != null) // can be null if implicitlyCA
    {
        ECCurve curve = spec.getParams().getCurve();
        EllipticCurve ellipticCurve;

        ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed());

        this.ecSpec = EC5Util.convertSpec(ellipticCurve, spec.getParams());
    }
    else
    {
        this.ecSpec = null;
    }

    this.configuration = configuration;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:25,代码来源:BCECPrivateKey.java

示例4: BCECGOST3410PrivateKey

import java.security.spec.ECPrivateKeySpec; //导入依赖的package包/类
public BCECGOST3410PrivateKey(
    org.bouncycastle.jce.spec.ECPrivateKeySpec spec)
{
    this.d = spec.getD();

    if (spec.getParams() != null) // can be null if implicitlyCA
    {
        ECCurve curve = spec.getParams().getCurve();
        EllipticCurve ellipticCurve;

        ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed());

        this.ecSpec = EC5Util.convertSpec(ellipticCurve, spec.getParams());
    }
    else
    {
        this.ecSpec = null;
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:20,代码来源:BCECGOST3410PrivateKey.java

示例5: getPrivateKey

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

示例6: getECPrivateKey

import java.security.spec.ECPrivateKeySpec; //导入依赖的package包/类
private static PrivateKey getECPrivateKey(String curve) throws Exception {
    String s;
    ECParameterSpec params;
    switch (curve) {
        case "P256":
            s = EC_P256_S;
            params = EC_P256_PARAMS;
            break;
        case "P384":
            s = EC_P384_S;
            params = EC_P384_PARAMS;
            break;
        case "P521":
            s = EC_P521_S;
            params = EC_P521_PARAMS;
            break;
        default:
            throw new Exception("Unsupported curve: " + curve);
    }
    KeyFactory kf = KeyFactory.getInstance("EC");
    KeySpec kspec = new ECPrivateKeySpec(new BigInteger(s), params);
    return kf.generatePrivate(kspec);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:GenerationTests.java

示例7: initChannelIdKey

import java.security.spec.ECPrivateKeySpec; //导入依赖的package包/类
private static synchronized void initChannelIdKey() throws Exception {
    if (CHANNEL_ID_PRIVATE_KEY != null) {
        return;
    }

    // NIST P-256 aka SECG secp256r1 aka X9.62 prime256v1
    OpenSSLECGroupContext openSslSpec = OpenSSLECGroupContext.getCurveByName("prime256v1");
    BigInteger s = new BigInteger(
            "229cdbbf489aea584828a261a23f9ff8b0f66f7ccac98bf2096ab3aee41497c5", 16);
    CHANNEL_ID_PRIVATE_KEY =
            new OpenSSLECPrivateKey(new ECPrivateKeySpec(s, openSslSpec.getECParameterSpec()))
                    .getOpenSSLKey();

    // Channel ID is the concatenation of the X and Y coordinates of the public key.
    CHANNEL_ID = new BigInteger(
            "702b07871fd7955c320b26f15e244e47eed60272124c92b9ebecf0b42f90069b"
                    + "ab53592ebfeb4f167dbf3ce61513afb0e354c479b1c1b69874fa471293494f77",
            16).toByteArray();
}
 
开发者ID:google,项目名称:conscrypt,代码行数:20,代码来源:NativeCryptoTest.java

示例8: toJcaPrivateKey

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

示例9: JCEECPrivateKey

import java.security.spec.ECPrivateKeySpec; //导入依赖的package包/类
public JCEECPrivateKey(
    String              algorithm,
    org.ripple.bouncycastle.jce.spec.ECPrivateKeySpec     spec)
{
    this.algorithm = algorithm;
    this.d = spec.getD();

    if (spec.getParams() != null) // can be null if implicitlyCA
    {
        ECCurve curve = spec.getParams().getCurve();
        EllipticCurve ellipticCurve;

        ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed());

        this.ecSpec = EC5Util.convertSpec(ellipticCurve, spec.getParams());
    }
    else
    {
        this.ecSpec = null;
    }
}
 
开发者ID:cping,项目名称:RipplePower,代码行数:22,代码来源:JCEECPrivateKey.java

示例10: BCDSTU4145PrivateKey

import java.security.spec.ECPrivateKeySpec; //导入依赖的package包/类
public BCDSTU4145PrivateKey(
    org.ripple.bouncycastle.jce.spec.ECPrivateKeySpec spec)
{
    this.d = spec.getD();

    if (spec.getParams() != null) // can be null if implicitlyCA
    {
        ECCurve curve = spec.getParams().getCurve();
        EllipticCurve ellipticCurve;

        ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed());

        this.ecSpec = EC5Util.convertSpec(ellipticCurve, spec.getParams());
    }
    else
    {
        this.ecSpec = null;
    }
}
 
开发者ID:cping,项目名称:RipplePower,代码行数:20,代码来源:BCDSTU4145PrivateKey.java

示例11: BCECPrivateKey

import java.security.spec.ECPrivateKeySpec; //导入依赖的package包/类
public BCECPrivateKey(
    String algorithm,
    org.ripple.bouncycastle.jce.spec.ECPrivateKeySpec spec,
    ProviderConfiguration configuration)
{
    this.algorithm = algorithm;
    this.d = spec.getD();

    if (spec.getParams() != null) // can be null if implicitlyCA
    {
        ECCurve curve = spec.getParams().getCurve();
        EllipticCurve ellipticCurve;

        ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed());

        this.ecSpec = EC5Util.convertSpec(ellipticCurve, spec.getParams());
    }
    else
    {
        this.ecSpec = null;
    }

    this.configuration = configuration;
}
 
开发者ID:cping,项目名称:RipplePower,代码行数:25,代码来源:BCECPrivateKey.java

示例12: BCECGOST3410PrivateKey

import java.security.spec.ECPrivateKeySpec; //导入依赖的package包/类
public BCECGOST3410PrivateKey(
    org.ripple.bouncycastle.jce.spec.ECPrivateKeySpec spec)
{
    this.d = spec.getD();

    if (spec.getParams() != null) // can be null if implicitlyCA
    {
        ECCurve curve = spec.getParams().getCurve();
        EllipticCurve ellipticCurve;

        ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed());

        this.ecSpec = EC5Util.convertSpec(ellipticCurve, spec.getParams());
    }
    else
    {
        this.ecSpec = null;
    }
}
 
开发者ID:cping,项目名称:RipplePower,代码行数:20,代码来源:BCECGOST3410PrivateKey.java

示例13: testGetParams

import java.security.spec.ECPrivateKeySpec; //导入依赖的package包/类
/**
 * Test for <code>getParams()</code> method<br>
 * Assertion: returns associated EC parameters<br>
 * Test preconditions: <code>ECPrivateKeySpec</code> instance
 * created using valid parameters<br>
 * Expected: must return params value which is equal
 * to the one passed to the constructor; (both must refer
 * the same object)
 */
public final void testGetParams() {
    // Valid (see note below) parameters set
    EllipticCurve c =
        new EllipticCurve(new ECFieldFp(BigInteger.valueOf(5L)),
                          BigInteger.ZERO,
                          BigInteger.valueOf(4L));
    ECPoint g = new ECPoint(BigInteger.ZERO, BigInteger.valueOf(2L));
    ECParameterSpec params =
        new ECParameterSpec(c, g, BigInteger.valueOf(5L), 10);

    ECPrivateKeySpec ks = new ECPrivateKeySpec(BigInteger.ZERO, params);
    ECParameterSpec paramsRet = ks.getParams();
    
    assertEquals(params, paramsRet);
    assertSame(params, paramsRet);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:26,代码来源:ECPrivateKeySpec_ImplTest.java

示例14: testGetS

import java.security.spec.ECPrivateKeySpec; //导入依赖的package包/类
/**
 * Test for <code>getS()</code> method<br>
 * Assertion: returns associated private value<br>
 * Test preconditions: <code>ECPrivateKeySpec</code> instance
 * created using valid parameters<br>
 * Expected: must return s value which is equal
 * to the one passed to the constructor; (both must refer
 * the same object)
 */
public final void testGetS() {
    // Valid (see note below) parameters set
    EllipticCurve c =
        new EllipticCurve(new ECFieldFp(BigInteger.valueOf(5L)),
                          BigInteger.ZERO,
                          BigInteger.valueOf(4L));
    ECPoint g = new ECPoint(BigInteger.ZERO, BigInteger.valueOf(2L));
    ECParameterSpec params =
        new ECParameterSpec(c, g, BigInteger.valueOf(5L), 10);
    BigInteger s = BigInteger.valueOf(5L);

    ECPrivateKeySpec ks = new ECPrivateKeySpec(s, params);
    BigInteger sRet = ks.getS();

    assertEquals(s, sRet);
    assertSame(s, sRet);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:27,代码来源:ECPrivateKeySpec_ImplTest.java

示例15: decrypt

import java.security.spec.ECPrivateKeySpec; //导入依赖的package包/类
/**
 * 解密<br>
 * 用私钥解密
 * 
 * @param data
 * @param key
 * @return
 * @throws Exception
 */
public static byte[] decrypt(byte[] data, String key) throws Exception {
    // 对密钥解密
    byte[] keyBytes = decryptBASE64(key);
 
    // 取得私钥
    PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes);
    KeyFactory keyFactory = ECKeyFactory.INSTANCE;
 
    ECPrivateKey priKey = (ECPrivateKey) keyFactory
            .generatePrivate(pkcs8KeySpec);
 
    ECPrivateKeySpec ecPrivateKeySpec = new ECPrivateKeySpec(priKey.getS(),
            priKey.getParams());
 
    // 对数据解密
    // TODO Chipher不支持EC算法 未能实现
    Cipher cipher = new NullCipher();
    // Cipher.getInstance(ALGORITHM, keyFactory.getProvider());
    cipher.init(Cipher.DECRYPT_MODE, priKey, ecPrivateKeySpec.getParams());
 
    return cipher.doFinal(data);
}
 
开发者ID:zhanggh,项目名称:mtools,代码行数:32,代码来源:ECCCoder.java


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