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


Java ECPrivateKeyImpl类代码示例

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


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

示例1: initKey

import sun.security.ec.ECPrivateKeyImpl; //导入依赖的package包/类
/**
 * 初始化密钥
 * 
 * @return
 * @throws Exception
 */
public static Map<String, Object> initKey() throws Exception {
    BigInteger x1 = new BigInteger(
            "2fe13c0537bbc11acaa07d793de4e6d5e5c94eee8", 16);
    BigInteger x2 = new BigInteger(
            "289070fb05d38ff58321f2e800536d538ccdaa3d9", 16);
 
    ECPoint g = new ECPoint(x1, x2);
 
    // the order of generator
    BigInteger n = new BigInteger(
            "5846006549323611672814741753598448348329118574063", 10);
    // the cofactor
    int h = 2;
    int m = 163;
    int[] ks = { 7, 6, 3 };
    ECFieldF2m ecField = new ECFieldF2m(m, ks);
    // y^2+xy=x^3+x^2+1
    BigInteger a = new BigInteger("1", 2);
    BigInteger b = new BigInteger("1", 2);
 
    EllipticCurve ellipticCurve = new EllipticCurve(ecField, a, b);
 
    ECParameterSpec ecParameterSpec = new ECParameterSpec(ellipticCurve, g,
            n, h);
    // 公钥
    ECPublicKey publicKey = new ECPublicKeyImpl(g, ecParameterSpec);
 
    BigInteger s = new BigInteger(
            "1234006549323611672814741753598448348329118574063", 10);
    // 私钥
    ECPrivateKey privateKey = new ECPrivateKeyImpl(s, ecParameterSpec);
 
    Map<String, Object> keyMap = new HashMap<String, Object>(2);
 
    keyMap.put(PUBLIC_KEY, publicKey);
    keyMap.put(PRIVATE_KEY, privateKey);
 
    return keyMap;
}
 
开发者ID:zhanggh,项目名称:mtools,代码行数:46,代码来源:ECCCoder.java

示例2: loadKeypair

import sun.security.ec.ECPrivateKeyImpl; //导入依赖的package包/类
@Override
public int loadKeypair(String s) {
    try {
        Key key = localKeyStore.getKey(s, new char[0]);
        if (key instanceof ECPrivateKeyImpl) {
            GuiHelper.setCertificateECPublicKey((ECPrivateKeyImpl) key);
        } else if (key instanceof RSAPrivateKey) {
            GuiHelper.setCertificateRSAPublicKey((RSAPrivateKey) key);
        }

        X509Certificate certificate = (X509Certificate) localKeyStore.getCertificate(s);
        currentCertificate = certificate;

        GuiHelper.setCertificateInfo(certificate);
        GuiHelper.setCertificateSubject(certificate.getSubjectX500Principal().getName());

        GuiHelper.setCertificateIssuer(certificate.getIssuerX500Principal().getName());
        GuiHelper.setCertificateExtensions(certificate);

        certificate.checkValidity();

        if (localKeyStore.entryInstanceOf(s, KeyStore.TrustedCertificateEntry.class)) {
            //trusted certificate
            return 2;
        } else if (CertificateHelper.isSelfSigned(certificate) && certificate.getBasicConstraints() == -1) {
            //certificate is self signed and not CA
            return 0;
        } else {
            //certificate is signed or CA
            return 1;
        }
    } catch (KeyStoreException | NoSuchAlgorithmException | UnrecoverableKeyException | IOException | ParseException
            | CertificateException e) {
        e.printStackTrace();
        return -1;
    }
}
 
开发者ID:stevanmilic,项目名称:X509-certificate-manager,代码行数:38,代码来源:MyCode.java

示例3: generateKeyPair

import sun.security.ec.ECPrivateKeyImpl; //导入依赖的package包/类
@Override
public KeyPair generateKeyPair() {

    byte[] encodedParams =
        ECUtil.encodeECParameterSpec(null, (ECParameterSpec)params);

    // seed is twice the key size (in bytes) plus 1
    byte[] seed = new byte[(((keySize + 7) >> 3) + 1) * 2];
    if (random == null) {
        random = JCAUtil.getSecureRandom();
    }
    random.nextBytes(seed);

    try {

        Object[] keyBytes = generateECKeyPair(keySize, encodedParams, seed);

        // The 'params' object supplied above is equivalent to the native
        // one so there is no need to fetch it.
        // keyBytes[0] is the encoding of the native private key
        BigInteger s = new BigInteger(1, (byte[])keyBytes[0]);

        PrivateKey privateKey =
            new ECPrivateKeyImpl(s, (ECParameterSpec)params);

        // keyBytes[1] is the encoding of the native public key
        ECPoint w = ECUtil.decodePoint((byte[])keyBytes[1],
            ((ECParameterSpec)params).getCurve());
        PublicKey publicKey =
            new ECPublicKeyImpl(w, (ECParameterSpec)params);

        return new KeyPair(publicKey, privateKey);

    } catch (Exception e) {
        throw new ProviderException(e);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:ECKeyPairGenerator.java

示例4: generateKeyPair

import sun.security.ec.ECPrivateKeyImpl; //导入依赖的package包/类
@Override
public KeyPair generateKeyPair() {

    byte[] encodedParams =
        ECParameters.encodeParameters((ECParameterSpec)params);

    // seed is twice the key size (in bytes) plus 1
    byte[] seed = new byte[(((keySize + 7) >> 3) + 1) * 2];
    if (random == null) {
        random = JCAUtil.getSecureRandom();
    }
    random.nextBytes(seed);

    try {

        long[] handles = generateECKeyPair(keySize, encodedParams, seed);

        // The 'params' object supplied above is equivalent to the native
        // one so there is no need to fetch it.

        // handles[0] points to the native private key
        BigInteger s = new BigInteger(1, getEncodedBytes(handles[0]));

        PrivateKey privateKey =
            new ECPrivateKeyImpl(s, (ECParameterSpec)params);

        // handles[1] points to the native public key
        ECPoint w = ECParameters.decodePoint(getEncodedBytes(handles[1]),
            ((ECParameterSpec)params).getCurve());
        PublicKey publicKey =
            new ECPublicKeyImpl(w, (ECParameterSpec)params);

        return new KeyPair(publicKey, privateKey);

    } catch (Exception e) {
        throw new ProviderException(e);
    }
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:39,代码来源:ECKeyPairGenerator.java

示例5: generateKeyPair

import sun.security.ec.ECPrivateKeyImpl; //导入依赖的package包/类
@Override
public KeyPair generateKeyPair() {

    byte[] encodedParams =
        ECUtil.encodeECParameterSpec(null, (ECParameterSpec)params);

    // seed is twice the key size (in bytes) plus 1
    byte[] seed = new byte[(((keySize + 7) >> 3) + 1) * 2];
    if (random == null) {
        random = JCAUtil.getSecureRandom();
    }
    random.nextBytes(seed);

    try {

        long[] handles = generateECKeyPair(keySize, encodedParams, seed);

        // The 'params' object supplied above is equivalent to the native
        // one so there is no need to fetch it.

        // handles[0] points to the native private key
        BigInteger s = new BigInteger(1, getEncodedBytes(handles[0]));

        PrivateKey privateKey =
            new ECPrivateKeyImpl(s, (ECParameterSpec)params);

        // handles[1] points to the native public key
        ECPoint w = ECUtil.decodePoint(getEncodedBytes(handles[1]),
            ((ECParameterSpec)params).getCurve());
        PublicKey publicKey =
            new ECPublicKeyImpl(w, (ECParameterSpec)params);

        return new KeyPair(publicKey, privateKey);

    } catch (Exception e) {
        throw new ProviderException(e);
    }
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:39,代码来源:ECKeyPairGenerator.java

示例6: setCertificateECPublicKey

import sun.security.ec.ECPrivateKeyImpl; //导入依赖的package包/类
static void setCertificateECPublicKey(ECPrivateKeyImpl privateKey) {
    access.setPublicKeyAlgorithm(privateKey.getAlgorithm());
    access.setPublicKeyECCurve(privateKey.getParams().getCurve().toString());
}
 
开发者ID:stevanmilic,项目名称:X509-certificate-manager,代码行数:5,代码来源:GuiHelper.java

示例7: initKey

import sun.security.ec.ECPrivateKeyImpl; //导入依赖的package包/类
/**
 * 初始化密钥
 * 
 * @return
 * @throws Exception
 */
public static Map<String, Object> initKey() throws Exception {
    BigInteger x1 = new BigInteger(
            "2fe13c0537bbc11acaa07d793de4e6d5e5c94eee8", 16);
    BigInteger x2 = new BigInteger(
            "289070fb05d38ff58321f2e800536d538ccdaa3d9", 16);

    ECPoint g = new ECPoint(x1, x2);

    // the order of generator
    BigInteger n = new BigInteger(
            "5846006549323611672814741753598448348329118574063", 10);
    // the cofactor
    int h = 2;
    int m = 163;
    int[] ks = {
            7, 6, 3
    };
    ECFieldF2m ecField = new ECFieldF2m(m, ks);
    // y^2+xy=x^3+x^2+1
    BigInteger a = new BigInteger("1", 2);
    BigInteger b = new BigInteger("1", 2);

    EllipticCurve ellipticCurve = new EllipticCurve(ecField, a, b);

    ECParameterSpec ecParameterSpec = new ECParameterSpec(ellipticCurve, g,
            n, h);
    // 公钥
    ECPublicKey publicKey = new ECPublicKeyImpl(g, ecParameterSpec);

    BigInteger s = new BigInteger(
            "1234006549323611672814741753598448348329118574063", 10);
    // 私钥
    ECPrivateKey privateKey = new ECPrivateKeyImpl(s, ecParameterSpec);

    Map<String, Object> keyMap = new HashMap<String, Object>(2);

    keyMap.put(PUBLIC_KEY, publicKey);
    keyMap.put(PRIVATE_KEY, privateKey);

    return keyMap;
}
 
开发者ID:cheyiliu,项目名称:test4java,代码行数:48,代码来源:ECCCoder.java


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