本文整理汇总了Java中sun.security.ec.ECParameters.encodePoint方法的典型用法代码示例。如果您正苦于以下问题:Java ECParameters.encodePoint方法的具体用法?Java ECParameters.encodePoint怎么用?Java ECParameters.encodePoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.security.ec.ECParameters
的用法示例。
在下文中一共展示了ECParameters.encodePoint方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
}
示例2: 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);
}
}
示例3: 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);
}
}
示例4: encodePoint
import sun.security.ec.ECParameters; //导入方法依赖的package包/类
static byte[] encodePoint(ECPoint point, EllipticCurve curve) {
return ECParameters.encodePoint(point, curve);
}