本文整理汇总了Java中java.security.spec.ECPoint类的典型用法代码示例。如果您正苦于以下问题:Java ECPoint类的具体用法?Java ECPoint怎么用?Java ECPoint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ECPoint类属于java.security.spec包,在下文中一共展示了ECPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertSpec
import java.security.spec.ECPoint; //导入依赖的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());
}
}
示例2: decodeTest
import java.security.spec.ECPoint; //导入依赖的package包/类
private void decodeTest()
{
EllipticCurve curve = new EllipticCurve(
new ECFieldFp(new BigInteger("6277101735386680763835789423207666416083908700390324961279")), // q
new BigInteger("fffffffffffffffffffffffffffffffefffffffffffffffc", 16), // a
new BigInteger("64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1", 16)); // b
ECPoint p = ECPointUtil.decodePoint(curve, Hex.decode("03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012"));
if (!p.getAffineX().equals(new BigInteger("188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012", 16)))
{
fail("x uncompressed incorrectly");
}
if (!p.getAffineY().equals(new BigInteger("7192b95ffc8da78631011ed6b24cdd573f977a11e794811", 16)))
{
fail("y uncompressed incorrectly");
}
}
示例3: decodeECCPublicKeyX509
import java.security.spec.ECPoint; //导入依赖的package包/类
/**
* Extract the raw bytes of the public ECC key in standard smart card format.
* @param publicKey the key to extract the bytes of.
* @param curveReference the reference to the standard curve of the key.
* @return the extract bytes of the key.
*/
public static byte[] decodeECCPublicKeyX509(PublicKey publicKey, EllipticCurveParameters curveReference)
{
byte[] publicKeyBytes = {};
if (publicKey instanceof ECPublicKey)
{
final ECPoint w = ((ECPublicKey)publicKey).getW();
final byte[] x = getStandardSizeInteger(w.getAffineX().toByteArray(), curveReference);
final byte[] y = getStandardSizeInteger(w.getAffineY().toByteArray(), curveReference);
publicKeyBytes = Bytes.concatenate(Bytes.bytes("04"), x, y); // Uncompressed format.
}
return publicKeyBytes;
}
示例4: encodeECParameterSpec
import java.security.spec.ECPoint; //导入依赖的package包/类
public static ECParameterSpec encodeECParameterSpec(EllipticCurveParameters params) {
// Field
final BigInteger pInt = new BigInteger(1, params.getP());
final ECField field = new ECFieldFp(pInt);
final BigInteger aInt = new BigInteger(1, params.getA());
final BigInteger bInt = new BigInteger(1, params.getB());
final EllipticCurve curve = new EllipticCurve(field, aInt, bInt);
// Fixed Point G
final BigInteger xInt = new BigInteger(1, params.getX());
final BigInteger yInt = new BigInteger(1, params.getY());
final ECPoint g = new ECPoint(xInt, yInt);
// Order N
final BigInteger nInt = new BigInteger(1, params.getN());
return new ECParameterSpec(curve, g, nInt, params.getH());
}
示例5: getQ
import java.security.spec.ECPoint; //导入依赖的package包/类
public org.bouncycastle.math.ec.ECPoint getQ()
{
if (ecSpec == null)
{
if (q instanceof org.bouncycastle.math.ec.ECPoint.Fp)
{
return new org.bouncycastle.math.ec.ECPoint.Fp(null, q.getX(), q.getY());
}
else
{
return new org.bouncycastle.math.ec.ECPoint.F2m(null, q.getX(), q.getY());
}
}
return q;
}
示例6: importBrowserAuthPublicKey
import java.security.spec.ECPoint; //导入依赖的package包/类
private static ECPublicKey importBrowserAuthPublicKey(String publicKey)
throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException
{
int xPos = publicKey.indexOf('x');
int yPos = publicKey.indexOf('y');
if (xPos != 0 || yPos < 0 || xPos >= yPos - 1 || publicKey.length() <= yPos + 2) {
throw new InvalidKeyException("Incorrectly formatted ECDH key.");
}
String x = publicKey.substring(publicKey.indexOf('x') + 1, publicKey.indexOf('y'));
String y = publicKey.substring(publicKey.indexOf('y') + 1);
KeyFactory kf = KeyFactory.getInstance("EC");
ECPoint point = new ECPoint(new BigInteger(x, 16), new BigInteger(y, 16));
ECPublicKey convertedPubKey = (ECPublicKey) kf.generatePublic(new ECPublicKeySpec(point, BROWSER_AUTH_EC_SPEC));
return convertedPubKey;
}
示例7: getPublicKey
import java.security.spec.ECPoint; //导入依赖的package包/类
/**
* Returns the ECPublicKey instance from its encoded raw bytes.
* The first byte has the fixed value 0x04 indicating the uncompressed form.
* Therefore, the byte array must be of form: [0x04, x coord of point (32 bytes), y coord of point (32 bytes)]
*
* @param publicKeyBytes The byte array representing the encoded raw bytes of the public key
* @return The ECPublicKey instance
*/
public static ECPublicKey getPublicKey(byte[] publicKeyBytes) {
// First we separate x and y of coordinates into separate variables
byte[] x = new byte[32];
byte[] y = new byte[32];
System.arraycopy(publicKeyBytes, 1, x, 0, 32);
System.arraycopy(publicKeyBytes, 33, y, 0, 32);
try {
KeyFactory kf = KeyFactory.getInstance("EC");
AlgorithmParameters parameters = AlgorithmParameters.getInstance("EC");
parameters.init(new ECGenParameterSpec("secp256r1"));
ECParameterSpec ecParameterSpec = parameters.getParameterSpec(ECParameterSpec.class);
ECPublicKeySpec ecPublicKeySpec = new ECPublicKeySpec(new ECPoint(new BigInteger(x), new BigInteger(y)), ecParameterSpec);
ECPublicKey ecPublicKey = (ECPublicKey) kf.generatePublic(ecPublicKeySpec);
return ecPublicKey;
} catch (NoSuchAlgorithmException | InvalidParameterSpecException | InvalidKeySpecException e) {
getLogger().error(e.getClass().getSimpleName() + " occurred when trying to get public key from raw bytes", e);
return null;
}
}
示例8: decodePoint
import java.security.spec.ECPoint; //导入依赖的package包/类
private static ECPoint decodePoint(byte[] data, EllipticCurve curve)
throws IOException {
if ((data.length == 0) || (data[0] != 4)) {
throw new IOException("Only uncompressed point format " +
"supported");
}
// Per ANSI X9.62, an encoded point is a 1 byte type followed by
// ceiling(log base 2 field-size / 8) bytes of x and the same of y.
int n = (data.length - 1) / 2;
if (n != ((curve.getField().getFieldSize() + 7) >> 3)) {
throw new IOException("Point does not match field size");
}
byte[] xb = Arrays.copyOfRange(data, 1, 1 + n);
byte[] yb = Arrays.copyOfRange(data, n + 1, n + 1 + n);
return new ECPoint(new BigInteger(1, xb), new BigInteger(1, yb));
}
示例9: loadEcPublicKey
import java.security.spec.ECPoint; //导入依赖的package包/类
private static Key loadEcPublicKey(final byte [] pubKey,
final EcCurve curveName) throws NoSuchAlgorithmException,
InvalidKeySpecException {
final ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(curveName.toString());
KeyFactory kf;
try {
kf = KeyFactory.getInstance(ECDH, BouncyCastleProvider.PROVIDER_NAME);
}
catch (final NoSuchProviderException e) {
kf = KeyFactory.getInstance(ECDH);
}
final ECNamedCurveSpec params = new ECNamedCurveSpec(curveName.toString(), spec.getCurve(), spec.getG(), spec.getN());
final ECPoint point = ECPointUtil.decodePoint(params.getCurve(), pubKey);
final java.security.spec.ECPublicKeySpec pubKeySpec = new java.security.spec.ECPublicKeySpec(point, params);
return kf.generatePublic(pubKeySpec);
}
示例10: getEcPoint
import java.security.spec.ECPoint; //导入依赖的package包/类
@Override
public AlgorithmParameterSpec getEcPoint(final byte[] nonceS, final byte[] sharedSecretH, final EcCurve curveName) {
final AlgorithmParameterSpec ecParams = ECNamedCurveTable.getParameterSpec(curveName.toString());
final BigInteger affineX = os2i(sharedSecretH);
final BigInteger affineY = computeAffineY(affineX, (ECParameterSpec) ecParams);
final ECPoint sharedSecretPointH = new ECPoint(affineX, affineY);
return mapNonceGMWithECDH(os2i(nonceS), sharedSecretPointH, (ECParameterSpec) ecParams);
}
示例11: mapNonceGMWithECDH
import java.security.spec.ECPoint; //导入依赖的package包/类
private static ECParameterSpec mapNonceGMWithECDH(final BigInteger nonceS,
final ECPoint sharedSecretPointH,
final ECParameterSpec params) {
// D~ = (p, a, b, G~, n, h) where G~ = [s]G + H
final ECPoint generator = params.getGenerator();
final EllipticCurve curve = params.getCurve();
final BigInteger a = curve.getA();
final BigInteger b = curve.getB();
final ECFieldFp field = (ECFieldFp)curve.getField();
final BigInteger p = field.getP();
final BigInteger order = params.getOrder();
final int cofactor = params.getCofactor();
final ECPoint ephemeralGenerator = add(multiply(nonceS, generator, params), sharedSecretPointH, params);
if (!toBouncyCastleECPoint(ephemeralGenerator, params).isValid()) {
LOGGER.warning("Se ha generado un punto invalido"); //$NON-NLS-1$
}
return new ECParameterSpec(new EllipticCurve(new ECFieldFp(p), a, b), ephemeralGenerator, order, cofactor);
}
示例12: mapNonceGMWithECDH
import java.security.spec.ECPoint; //导入依赖的package包/类
private static ECParameterSpec mapNonceGMWithECDH(final BigInteger nonceS,
final ECPoint sharedSecretPointH,
final ECParameterSpec params) {
// D~ = (p, a, b, G~, n, h) where G~ = [s]G + H
final ECPoint generator = params.getGenerator();
final EllipticCurve curve = params.getCurve();
final BigInteger a = curve.getA();
final BigInteger b = curve.getB();
final ECFieldFp field = (ECFieldFp)curve.getField();
final BigInteger p = field.getP();
final BigInteger order = params.getOrder();
final int cofactor = params.getCofactor();
final ECPoint ephemeralGenerator = add(multiply(nonceS, generator, params), sharedSecretPointH, params);
if (!toSpongyCastleECPoint(ephemeralGenerator, params).isValid()) {
LOGGER.warning("Se ha generado un punto invalido"); //$NON-NLS-1$
}
return new ECParameterSpec(new EllipticCurve(new ECFieldFp(p), a, b), ephemeralGenerator, order, cofactor);
}
示例13: CfcaCurve
import java.security.spec.ECPoint; //导入依赖的package包/类
public static ECParameterSpec CfcaCurve() {
// 素数P
BigInteger p = new BigInteger("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF", 16);
// 基于素数P的有限域
ECFieldFp gfp = new ECFieldFp(p);
// 在有限域上的椭圆曲线y2 = x3 + ax + b
EllipticCurve ellipticCurve = new EllipticCurve(gfp,
new BigInteger("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC", 16),
new BigInteger("28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93", 16));
// 基点G
ECPoint G = new ECPoint(new BigInteger("32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7", 16),
new BigInteger("BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0", 16));
// G的阶
BigInteger n = new BigInteger("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123", 16);
// 设置基点
ECParameterSpec ecParameterSpec = new ECParameterSpec(ellipticCurve, G, n, 1);
return ecParameterSpec;
}
示例14: getECParameterSpec
import java.security.spec.ECPoint; //导入依赖的package包/类
ECParameterSpec getECParameterSpec() {
final String curveName = NativeCrypto.EC_GROUP_get_curve_name(groupCtx);
final byte[][] curveParams = NativeCrypto.EC_GROUP_get_curve(groupCtx);
final BigInteger p = new BigInteger(curveParams[0]);
final BigInteger a = new BigInteger(curveParams[1]);
final BigInteger b = new BigInteger(curveParams[2]);
final ECField field = new ECFieldFp(p);
final EllipticCurve curve = new EllipticCurve(field, a, b);
final OpenSSLECPointContext generatorCtx = new OpenSSLECPointContext(this,
new NativeRef.EC_POINT(NativeCrypto.EC_GROUP_get_generator(groupCtx)));
final ECPoint generator = generatorCtx.getECPoint();
final BigInteger order = new BigInteger(NativeCrypto.EC_GROUP_get_order(groupCtx));
final BigInteger cofactor = new BigInteger(NativeCrypto.EC_GROUP_get_cofactor(groupCtx));
ECParameterSpec spec = new ECParameterSpec(curve, generator, order, cofactor.intValue());
Platform.setCurveName(spec, curveName);
return spec;
}
示例15: publicKeyToBytes
import java.security.spec.ECPoint; //导入依赖的package包/类
/**
* Converts the ECDH public key to bytes (has to be 65 bytes in length)
* @param publicKey Public key for ECDH p256 curve
* @return bytearray representation of key
*/
public byte[] publicKeyToBytes(final ECPublicKey publicKey) throws DecoderException {
ECPoint point = publicKey.getW();
String x = point.getAffineX().toString(16);
String y = point.getAffineY().toString(16);
/*
* Format is 04 followed by 32 bytes (64 hex) each for the X,Y coordinates
*/
StringBuilder sb = new StringBuilder();
sb.append("04");
for (int i = 0; i < 64 - x.length(); i++) {
sb.append(0);
}
sb.append(x);
for (int i = 0; i < 64 - y.length(); i++) {
sb.append(0);
}
sb.append(y);
return decodeHex(sb.toString().toCharArray());
}