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


Java ECPoint类代码示例

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


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

示例1: sm2Verify

import org.bouncycastle.math.ec.ECPoint; //导入依赖的package包/类
public void sm2Verify(byte md[], ECPoint userKey, BigInteger r, BigInteger s, SM2Result sm2Result) {
    sm2Result.R = null;
    BigInteger e = new BigInteger(1, md);
    BigInteger t = r.add(s).mod(ecc_n);
    if (t.equals(BigInteger.ZERO)) {
        return;
    } else {
        ECPoint x1y1 = ecc_point_g.multiply(sm2Result.s);
        System.out.println("X0: " + x1y1.getX().toBigInteger().toString(16));
        System.out.println("Y0: " + x1y1.getY().toBigInteger().toString(16));
        System.out.println("");

        x1y1 = x1y1.add(userKey.multiply(t));
        System.out.println("X1: " + x1y1.getX().toBigInteger().toString(16));
        System.out.println("Y1: " + x1y1.getY().toBigInteger().toString(16));
        System.out.println("");
        sm2Result.R = e.add(x1y1.getX().toBigInteger()).mod(ecc_n);
        System.out.println("R: " + sm2Result.R.toString(16));
        return;
    }
}
 
开发者ID:nuls-io,项目名称:nuls,代码行数:22,代码来源:SM2.java

示例2: unpackEcPoint

import org.bouncycastle.math.ec.ECPoint; //导入依赖的package包/类
public static ECPoint unpackEcPoint(Value value) throws IOException {
    if (!value.isExtensionValue())
        throw new RuntimeException("Expected extension value");

    ExtensionValue extValue = value.asExtensionValue();
    if (extValue.getType() != 2)
        throw new RuntimeException("Expected ecpoint value");

    byte[] data = extValue.getData();

    MessageUnpacker unpacker = MessagePack.DEFAULT_UNPACKER_CONFIG.newUnpacker(data);
    ArrayValue array = unpacker.unpackValue().asArrayValue();
    int id = array.get(0).asIntegerValue().asInt();
    // We only support secp224r1 at the moment.
    assert id == 713;
    byte[] ecData = array.get(1).asBinaryValue().asByteArray();
    ECPoint point = new GroupECC().EcSpec.getCurve().decodePoint(ecData);
    return point;
}
 
开发者ID:cheahjs,项目名称:JLoopix,代码行数:20,代码来源:Unpacker.java

示例3: readECPoint

import org.bouncycastle.math.ec.ECPoint; //导入依赖的package包/类
public ECPoint readECPoint() throws IOException {
	byte[] encoded;
	byte fb = reader.readByte();
	switch (fb)
	{
	case 0x00:
		encoded = new byte[1];
		break;
	case 0x02:
	case 0x03:
		encoded = new byte[33];
		encoded[0] = fb;
		reader.readFully(encoded, 1, 32);
		break;
	case 0x04:
		encoded = new byte[65];
		encoded[0] = fb;
		reader.readFully(encoded, 1, 64);
		break;
	default:
		throw new IOException();
	}
	return ECC.secp256r1.getCurve().decodePoint(encoded);
}
 
开发者ID:DNAProject,项目名称:DNASDKJava,代码行数:25,代码来源:BinaryReader.java

示例4: createParameters

import org.bouncycastle.math.ec.ECPoint; //导入依赖的package包/类
protected X9ECParameters createParameters()
{
    int m = 131;
    int k1 = 2;
    int k2 = 3;
    int k3 = 8;

    BigInteger a = fromHex("03E5A88919D7CAFCBF415F07C2176573B2");
    BigInteger b = fromHex("04B8266A46C55657AC734CE38F018F2192");
    byte[] S = Hex.decode("985BD3ADBAD4D696E676875615175A21B43A97E3");
    BigInteger n = fromHex("0400000000000000016954A233049BA98F");
    BigInteger h = BigInteger.valueOf(2);

    ECCurve curve = new ECCurve.F2m(m, k1, k2, k3, a, b, n, h);
    //ECPoint G = curve.decodePoint(Hex.decode("03"
    //+ "0356DCD8F2F95031AD652D23951BB366A8"));
    ECPoint G = curve.decodePoint(Hex.decode("04"
        + "0356DCD8F2F95031AD652D23951BB366A8"
        + "0648F06D867940A5366D9E265DE9EB240F"));

    return new X9ECParameters(curve, G, n, h, S);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:23,代码来源:SECNamedCurves.java

示例5: print

import org.bouncycastle.math.ec.ECPoint; //导入依赖的package包/类
public static void print(Account acc) {
	// addr
	print("acc..................st");
	print("acc.addr:"+Wallet.toAddress(Program.toScriptHash(Contract.createSignatureRedeemScript(acc.publicKey))));
	print("acc.uint:"+Program.toScriptHash(Contract.createSignatureRedeemScript(acc.publicKey)).toString());
	print("acc.uint(byte):"+getbyteStr(Program.toScriptHash(Contract.createSignatureRedeemScript(acc.publicKey)).toArray()));
	print("acc.uint(hex):"+toHexString(Program.toScriptHash(Contract.createSignatureRedeemScript(acc.publicKey)).toArray()));
	// pubKey
	ECPoint pubKey = acc.publicKey;
	String pubKeyStr = toHexString(acc.publicKey.getEncoded(true));
	print(String.format("acc.PubKey:\n\tECPoint: %s\n\tPubKStr:%s", pubKey, pubKeyStr));
	
	// priKey
	String priKey = toHexString(acc.privateKey);
	print(String.format("acc.PriKey:\n\tHEX:%s", priKey));
	
	String wif = acc.export();
	print(String.format("\tWIF:%s", wif));
	
	// pubKeyHash
	print("acc.PubKeyHash:"+acc.publicKeyHash.toString());
	print("acc..................ed");
}
 
开发者ID:DNAProject,项目名称:DNASDKJava,代码行数:24,代码来源:OnChainSDKHelper.java

示例6: ECPointDeSerialization

import org.bouncycastle.math.ec.ECPoint; //导入依赖的package包/类
public static ECPoint ECPointDeSerialization(ECCurve curve, byte[] serialized_point, int offset) {

        byte[] x_b = new byte[256 / 8];
        byte[] y_b = new byte[256 / 8];

		// System.out.println("Serialized Point: " + toHex(serialized_point));
        // src -- This is the source array.
        // srcPos -- This is the starting position in the source array.
        // dest -- This is the destination array.
        // destPos -- This is the starting position in the destination data.
        // length -- This is the number of array elements to be copied.
        System.arraycopy(serialized_point, offset + 1, x_b, 0, Consts.SHARE_BASIC_SIZE);
        BigInteger x = new BigInteger(bytesToHex(x_b), 16);
        // System.out.println("X:" + toHex(x_b));
        System.arraycopy(serialized_point, offset + (Consts.SHARE_BASIC_SIZE + 1), y_b, 0, Consts.SHARE_BASIC_SIZE);
        BigInteger y = new BigInteger(bytesToHex(y_b), 16);
        // System.out.println("Y:" + toHex(y_b));

        ECPoint point = curve.createPoint(x, y);

        return point;
    }
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:23,代码来源:Util.java

示例7: getParams

import org.bouncycastle.math.ec.ECPoint; //导入依赖的package包/类
private ECParameterSpec getParams(ECDSAPublicKey key)
{
    if (!key.hasParameters())
    {
        throw new IllegalArgumentException("Public key does not contains EC Params");
    }

    BigInteger p = key.getPrimeModulusP();
    ECCurve.Fp curve = new ECCurve.Fp(p, key.getFirstCoefA(), key.getSecondCoefB());

    ECPoint G = curve.decodePoint(key.getBasePointG());

    BigInteger order = key.getOrderOfBasePointR();
    BigInteger coFactor = key.getCofactorF();
               // TODO: update to use JDK 1.5 EC API
    ECParameterSpec ecspec = new ECParameterSpec(curve, G, order, coFactor);

    return ecspec;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:20,代码来源:JcaPublicKeyConverter.java

示例8: Verify

import org.bouncycastle.math.ec.ECPoint; //导入依赖的package包/类
private static boolean Verify(byte[] plaintext, ECPoint pubkey, BigInteger s_bi, BigInteger e_bi) throws Exception {

        // Compute rv = sG+eY
        ECPoint rv_EC = mpcGlobals.G.multiply(s_bi); // sG
        rv_EC = rv_EC.add(pubkey.multiply(e_bi)); // +eY

        // Compute ev = H(m||rv)
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.update(plaintext);
        md.update(rv_EC.getEncoded(false));
        byte[] ev = md.digest();
        BigInteger ev_bi = new BigInteger(1, ev);
        ev_bi = ev_bi.mod(mpcGlobals.n);

        ///System.out.println(bytesToHex(e_bi.toByteArray()));		
        //System.out.println(bytesToHex(ev_bi.toByteArray()));
        if (_FAIL_ON_ASSERT) {
            assert (e_bi.compareTo(ev_bi) == 0);
        }
        // compare ev with e
        return e_bi.compareTo(ev_bi) == 0;
    }
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:23,代码来源:MPCTestClient.java

示例9: transform

import org.bouncycastle.math.ec.ECPoint; //导入依赖的package包/类
/**
 * Transform an existing cipher test pair using the ElGamal algorithm. Note: the input cipherText will
 * need to be preserved in order to complete the transformation to the new public key.
 *
 * @param cipherText the EC point to process.
 * @return returns a new ECPair representing the result of the process.
 */
public ECPair transform(ECPair cipherText)
{
    if (key == null)
    {
        throw new IllegalStateException("ECNewPublicKeyTransform not initialised");
    }

    BigInteger             n = key.getParameters().getN();
    BigInteger             k = ECUtil.generateK(n, random);

    ECPoint  g = key.getParameters().getG();
    ECPoint  gamma = g.multiply(k);
    ECPoint  phi = key.getQ().multiply(k).add(cipherText.getY());

    return new ECPair(gamma, phi);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:24,代码来源:ECNewPublicKeyTransform.java

示例10: transform

import org.bouncycastle.math.ec.ECPoint; //导入依赖的package包/类
/**
 * Transform an existing cipher test pair using the ElGamal algorithm. Note: it is assumed this
 * transform has been initialised with the same public key that was used to create the original
 * cipher text.
 *
 * @param cipherText the EC point to process.
 * @return returns a new ECPair representing the result of the process.
 */
public ECPair transform(ECPair cipherText)
{
    if (key == null)
    {
        throw new IllegalStateException("ECNewRandomnessTransform not initialised");
    }

    BigInteger             n = key.getParameters().getN();
    BigInteger             k = ECUtil.generateK(n, random);

    ECPoint  g = key.getParameters().getG();
    ECPoint  gamma = g.multiply(k);
    ECPoint  phi = key.getQ().multiply(k).add(cipherText.getY());

    return new ECPair(cipherText.getX().add(gamma), phi);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:25,代码来源:ECNewRandomnessTransform.java

示例11: encrypt

import org.bouncycastle.math.ec.ECPoint; //导入依赖的package包/类
/**
 * Process a single EC point using the basic ElGamal algorithm.
 *
 * @param point the EC point to process.
 * @return the result of the Elgamal process.
 */
public ECPair encrypt(ECPoint point)
{
    if (key == null)
    {
        throw new IllegalStateException("ECElGamalEncryptor not initialised");
    }

    BigInteger             n = key.getParameters().getN();
    BigInteger             k = ECUtil.generateK(n, random);

    ECPoint  g = key.getParameters().getG();
    ECPoint  gamma = g.multiply(k);
    ECPoint  phi = key.getQ().multiply(k).add(point);

    return new ECPair(gamma, phi);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:23,代码来源:ECElGamalEncryptor.java

示例12: Sign

import org.bouncycastle.math.ec.ECPoint; //导入依赖的package包/类
private BigInteger Sign(Bignat i, ECPoint R_EC, byte[] plaintext) throws NoSuchAlgorithmException {
    //Gen e (e will be the same in all signature shares)
    MessageDigest md = MessageDigest.getInstance("SHA-256");
    //System.out.println("Simulated: Plaintext:" + client.bytesToHex(plaintext));
    //System.out.println("Simulated: Ri,n:     " + client.bytesToHex(R_EC.getEncoded(false)));
    md.update(plaintext);
    md.update(R_EC.getEncoded(false)); // R_EC is the sum of the r_i's
    byte[] e = md.digest();
    BigInteger e_BI = new BigInteger(1, e);

    //Gen s_i
    this.k_Bn = new BigInteger(PRF(i, secret_seed));

    BigInteger s_i_BI = this.k_Bn.subtract(e_BI.multiply(this.priv_key_BI));
    s_i_BI = s_i_BI.mod(curve_n);

    /* BUGBUG: I'm cheating a bit here, and use the e returned by the JC.
     Btw e is always the same, so it can actually be computed 
     on the host if this helps with optimizing the applet */
    //System.out.println("Simulated: s:        " + client.bytesToHex(s_i_BI.toByteArray()));
    //System.out.println("Simulated: e:        " + client.bytesToHex(e) + "\n");
    return s_i_BI;
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:24,代码来源:SimulatedMPCPlayer.java

示例13: calculatePoint

import org.bouncycastle.math.ec.ECPoint; //导入依赖的package包/类
public ECPoint calculatePoint(CipherParameters pubKey) {
    ECPublicKeyParameters pub = (ECPublicKeyParameters) pubKey;
    ECPoint P = pub.getQ().multiply(key.getD()).normalize();

    if (P.isInfinity()) {
        throw new IllegalStateException("Infinity is not a valid agreement value for ECDH");
    }
    return P;
}
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:10,代码来源:ECKABasicAgreement.java

示例14: decodeKeyPair

import org.bouncycastle.math.ec.ECPoint; //导入依赖的package包/类
public static KeyPair decodeKeyPair(ECKeyPair ecKeyPair) {
    byte[] bytes = Numeric.toBytesPadded(ecKeyPair.getPublicKey(), 64);
    BigInteger x = Numeric.toBigInt(Arrays.copyOfRange(bytes, 0, 32));
    BigInteger y = Numeric.toBigInt(Arrays.copyOfRange(bytes, 32, 64));
    ECPoint q = curve.createPoint(x, y);
    BCECPublicKey publicKey = new BCECPublicKey(ALGORITHM, new ECPublicKeyParameters(q, dp), BouncyCastleProvider.CONFIGURATION);
    BCECPrivateKey privateKey = new BCECPrivateKey(ALGORITHM, new ECPrivateKeyParameters(ecKeyPair.getPrivateKey(), dp), publicKey, p, BouncyCastleProvider.CONFIGURATION);
    return new KeyPair(publicKey, privateKey);
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:10,代码来源:CryptoUtil.java

示例15: X9ECParameters

import org.bouncycastle.math.ec.ECPoint; //导入依赖的package包/类
public X9ECParameters(
    ECCurve     curve,
    ECPoint     g,
    BigInteger  n)
{
    this(curve, g, n, ONE, null);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:8,代码来源:X9ECParameters.java


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