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


Java ECParameters类代码示例

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


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

示例1: initialize

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

    if (params instanceof ECParameterSpec) {
        this.params = ECParameters.getNamedCurve((ECParameterSpec)params);
        if (this.params == null) {
            throw new InvalidAlgorithmParameterException(
                "Unsupported curve: " + params);
        }
    } else if (params instanceof ECGenParameterSpec) {
        String name = ((ECGenParameterSpec)params).getName();
        this.params = NamedCurve.getECParameterSpec(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:openjdk,项目名称:jdk7-jdk,代码行数:26,代码来源:ECKeyPairGenerator.java

示例2: generatePrivate

import sun.security.ec.ECParameters; //导入依赖的package包/类
private PrivateKey generatePrivate(BigInteger s, ECParameterSpec params) throws PKCS11Exception {
    byte[] encodedParams = ECParameters.encodeParameters(params);
    CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
        new CK_ATTRIBUTE(CKA_CLASS, CKO_PRIVATE_KEY),
        new CK_ATTRIBUTE(CKA_KEY_TYPE, CKK_EC),
        new CK_ATTRIBUTE(CKA_VALUE, s),
        new CK_ATTRIBUTE(CKA_EC_PARAMS, encodedParams),
    };
    attributes = token.getAttributes
            (O_IMPORT, CKO_PRIVATE_KEY, CKK_EC, attributes);
    Session session = null;
    try {
        session = token.getObjSession();
        long keyID = token.p11.C_CreateObject(session.id(), attributes);
        return P11Key.privateKey
            (session, keyID, "EC", params.getCurve().getField().getFieldSize(), attributes);
    } finally {
        token.releaseSession(session);
    }
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:21,代码来源:P11ECKeyFactory.java

示例3: getNamedCurveOid

import sun.security.ec.ECParameters; //导入依赖的package包/类
static String getNamedCurveOid(ECParameterSpec params) {
    return ECParameters.getCurveName(params);
}
 
开发者ID:alexkasko,项目名称:openjdk-icedtea7,代码行数:4,代码来源:JsseJce.java

示例4: generateKeyPair

import sun.security.ec.ECParameters; //导入依赖的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: getEncodedPublicValue

import sun.security.ec.ECParameters; //导入依赖的package包/类
static byte[] getEncodedPublicValue(PublicKey key) throws InvalidKeyException {
    if (key instanceof ECPublicKeyImpl) {
        return ((ECPublicKeyImpl)key).getEncodedPublicValue();
    } else if (key instanceof ECPublicKey) {
        ECPublicKey ecKey = (ECPublicKey)key;
        ECPoint w = ecKey.getW();
        ECParameterSpec params = ecKey.getParams();
        return ECParameters.encodePoint(w, params.getCurve());
    } else {
        // should never occur
        throw new InvalidKeyException
            ("Key class not yet supported: " + key.getClass().getName());
    }
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:15,代码来源:P11ECKeyFactory.java

示例6: generatePublic

import sun.security.ec.ECParameters; //导入依赖的package包/类
private PublicKey generatePublic(ECPoint point, ECParameterSpec params) throws PKCS11Exception {
    byte[] encodedParams = ECParameters.encodeParameters(params);
    byte[] encodedPoint = null;
    DerValue pkECPoint = new DerValue(DerValue.tag_OctetString,
        ECParameters.encodePoint(point, params.getCurve()));

    try {
        encodedPoint = pkECPoint.toByteArray();
    } catch (IOException e) {
        throw new IllegalArgumentException("Could not DER encode point", e);
    }

    CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
        new CK_ATTRIBUTE(CKA_CLASS, CKO_PUBLIC_KEY),
        new CK_ATTRIBUTE(CKA_KEY_TYPE, CKK_EC),
        new CK_ATTRIBUTE(CKA_EC_POINT, encodedPoint),
        new CK_ATTRIBUTE(CKA_EC_PARAMS, encodedParams),
    };
    attributes = token.getAttributes
            (O_IMPORT, CKO_PUBLIC_KEY, CKK_EC, attributes);
    Session session = null;
    try {
        session = token.getObjSession();
        long keyID = token.p11.C_CreateObject(session.id(), attributes);
        return P11Key.publicKey
            (session, keyID, "EC", params.getCurve().getField().getFieldSize(), attributes);
    } finally {
        token.releaseSession(session);
    }
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:31,代码来源:P11ECKeyFactory.java

示例7: generatePublic

import sun.security.ec.ECParameters; //导入依赖的package包/类
private PublicKey generatePublic(ECPoint point, ECParameterSpec params) throws PKCS11Exception {
    byte[] encodedParams = ECParameters.encodeParameters(params);
    byte[] encodedPoint =
        ECParameters.encodePoint(point, params.getCurve());

    // Check whether the X9.63 encoding of an EC point shall be wrapped
    // in an ASN.1 OCTET STRING
    if (!token.config.getUseEcX963Encoding()) {
        try {
            encodedPoint =
                new DerValue(DerValue.tag_OctetString, encodedPoint)
                    .toByteArray();
        } catch (IOException e) {
            throw new
                IllegalArgumentException("Could not DER encode point", e);
        }
    }

    CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
        new CK_ATTRIBUTE(CKA_CLASS, CKO_PUBLIC_KEY),
        new CK_ATTRIBUTE(CKA_KEY_TYPE, CKK_EC),
        new CK_ATTRIBUTE(CKA_EC_POINT, encodedPoint),
        new CK_ATTRIBUTE(CKA_EC_PARAMS, encodedParams),
    };
    attributes = token.getAttributes
            (O_IMPORT, CKO_PUBLIC_KEY, CKK_EC, attributes);
    Session session = null;
    try {
        session = token.getObjSession();
        long keyID = token.p11.C_CreateObject(session.id(), attributes);
        return P11Key.publicKey
            (session, keyID, "EC", params.getCurve().getField().getFieldSize(), attributes);
    } finally {
        token.releaseSession(session);
    }
}
 
开发者ID:greghaskins,项目名称:openjdk-jdk7u-jdk,代码行数:37,代码来源:P11ECKeyFactory.java

示例8: decodePoint

import sun.security.ec.ECParameters; //导入依赖的package包/类
static ECPoint decodePoint(byte[] encoded, EllipticCurve curve)
        throws java.io.IOException {
    return ECParameters.decodePoint(encoded, curve);
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:5,代码来源:JsseJce.java

示例9: encodePoint

import sun.security.ec.ECParameters; //导入依赖的package包/类
static byte[] encodePoint(ECPoint point, EllipticCurve curve) {
    return ECParameters.encodePoint(point, curve);
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:4,代码来源:JsseJce.java

示例10: getECParameterSpec

import sun.security.ec.ECParameters; //导入依赖的package包/类
static ECParameterSpec getECParameterSpec(ECParameterSpec spec) {
    return ECParameters.getNamedCurve(spec);
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:4,代码来源:P11ECKeyFactory.java

示例11: decodeParameters

import sun.security.ec.ECParameters; //导入依赖的package包/类
static ECParameterSpec decodeParameters(byte[] params) throws IOException {
    return ECParameters.decodeParameters(params);
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:4,代码来源:P11ECKeyFactory.java

示例12: encodeParameters

import sun.security.ec.ECParameters; //导入依赖的package包/类
static byte[] encodeParameters(ECParameterSpec params) {
    return ECParameters.encodeParameters(params);
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:4,代码来源:P11ECKeyFactory.java

示例13: decodePoint

import sun.security.ec.ECParameters; //导入依赖的package包/类
static ECPoint decodePoint(byte[] encoded, EllipticCurve curve) throws IOException {
    return ECParameters.decodePoint(encoded, curve);
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:4,代码来源:P11ECKeyFactory.java


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