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


Java BigInteger.equals方法代码示例

本文整理汇总了Java中java.math.BigInteger.equals方法的典型用法代码示例。如果您正苦于以下问题:Java BigInteger.equals方法的具体用法?Java BigInteger.equals怎么用?Java BigInteger.equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.math.BigInteger的用法示例。


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

示例1: getCertificate

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Returns the X.509 certificate listed in this PKCS7 block
 * which has a matching serial number and Issuer name, or
 * null if one is not found.
 *
 * @param serial the serial number of the certificate to retrieve.
 * @param issuerName the Distinguished Name of the Issuer.
 */
public X509Certificate getCertificate(BigInteger serial, X500Name issuerName) {
    if (certificates != null) {
        if (certIssuerNames == null)
            populateCertIssuerNames();
        for (int i = 0; i < certificates.length; i++) {
            X509Certificate cert = certificates[i];
            BigInteger thisSerial = cert.getSerialNumber();
            if (serial.equals(thisSerial)
                && issuerName.equals(certIssuerNames[i]))
            {
                return cert;
            }
        }
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:PKCS7.java

示例2: writeLargeBig

import java.math.BigInteger; //导入方法依赖的package包/类
public ETFWriter writeLargeBig(BigInteger num) {
    if (num.equals(BigInteger.ZERO)) {
        writeToBuffer(LARGE_BIG_EXT, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0);
    } else {
        byte signum = num.signum() == -1 ? (byte) 1 : (byte) 0;
        num = num.abs();
        int n = (int) Math.ceil(num.bitLength()/8)+1; //Equivalent to Math.ceil(log256(num)) + 1
        byte[] bytes = new byte[n];
        writeToBuffer(LARGE_BIG_EXT, (byte) ((n >>> 24) & 0xFF), (byte) ((n >>> 16) & 0xFF),
                (byte) ((n >>> 8) & 0xFF), (byte) (n & 0xFF), signum);
        n -= 1;
        while (n >= 0) {
            BigInteger[] res = num.divideAndRemainder(BigInteger.valueOf(256).pow(n));
            bytes[n] = res[0].byteValue(); //Quotient
            num = res[1]; //Remainder
            n--;
        }
        writeToBuffer(bytes);
    }
    return this;
}
 
开发者ID:austinv11,项目名称:ETF-Java,代码行数:22,代码来源:ETFWriter.java

示例3: toBytes

import java.math.BigInteger; //导入方法依赖的package包/类
private static byte[] toBytes(Object input) {
    if (input instanceof byte[]) {
        return (byte[]) input;
    } else if (input instanceof String) {
        String inputString = (String) input;
        return inputString.getBytes();
    } else if (input instanceof Long) {
        Long inputLong = (Long) input;
        return (inputLong == 0) ? ByteUtil.EMPTY_BYTE_ARRAY : asUnsignedByteArray(BigInteger.valueOf(inputLong));
    } else if (input instanceof Integer) {
        Integer inputInt = (Integer) input;
        return (inputInt == 0) ? ByteUtil.EMPTY_BYTE_ARRAY : asUnsignedByteArray(BigInteger.valueOf(inputInt));
    } else if (input instanceof BigInteger) {
        BigInteger inputBigInt = (BigInteger) input;
        return (inputBigInt.equals(BigInteger.ZERO)) ? ByteUtil.EMPTY_BYTE_ARRAY : asUnsignedByteArray(inputBigInt);
    } else if (input instanceof Value) {
        Value val = (Value) input;
        return toBytes(val.asObj());
    }
    throw new RuntimeException("Unsupported type: Only accepting String, Integer and BigInteger for now");
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:22,代码来源:RLP.java

示例4: retrieveTally

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Method to chop down the result in order to get the vote results. This
 * application used base 10. To concatenate the resulting output in one
 * string. Needs only to be displayed at the screen.
 * 
 * @param decryptedTally
 * @return results - String
 */
public String retrieveTally(BigInteger decryptedTally) {

	if (decryptedTally.equals(BigInteger.ZERO))
		return "No candidates selected";

	String s = " ";
	String w = "\n\nOr each candidate has:\n\n";
	List<Integer> list = new ArrayList<Integer>();
	BigInteger ten = new BigInteger("10");
	while (!decryptedTally.equals(BigInteger.ZERO)) {
		list.add(0, decryptedTally.mod(ten).intValue());
		decryptedTally = decryptedTally.divide(ten);
	}
	// using enum class to get the String representation(the base) for each
	// candidate
	Candidates[] candidates = Candidates.values();
	for (int i = 0; i < list.size(); i++) {
		if (i < list.size() - 1) {
			s = s + list.get(i).toString() + "*"
					+ candidates[list.size() - i - 1].getExp() + " + ";
			w = w + list.get(i).toString() + " vote(s) for "
					+ candidates[list.size() - i - 1].getName() + "\n";
		} else {
			s = s + list.get(i).toString() + "*"
					+ candidates[list.size() - i - 1].getExp();
			w = w + list.get(i).toString() + " vote(s) for "
					+ candidates[list.size() - i - 1].getName();
		}
	}
	return s + w;
}
 
开发者ID:peterstefanov,项目名称:paillier,代码行数:40,代码来源:GUI.java

示例5: getYValue

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Algorithm 7.9: GetYValue
 * <p>Generates the coefficients a_0, ..., a_d of a random polynomial</p>
 *
 * @param x value in Z_p_prime
 * @param bold_a the coefficients of the polynomial
 * @return the computed value y
 */
public BigInteger getYValue(BigInteger x, List<BigInteger> bold_a) {
    Preconditions.checkArgument(bold_a.size() >= 1,
            String.format("The size of bold_a should always be larger or equal to 1 (it is [%d]", bold_a.size()));
    if (x.equals(BigInteger.ZERO)) {
        return bold_a.get(0);
    } else {
        BigInteger y = BigInteger.ZERO;
        for (BigInteger a_i : Lists.reverse(bold_a)) {
            y = a_i.add(x.multiply(y).mod(primeField.getP_prime())).mod(primeField.getP_prime());
        }
        return y;
    }
}
 
开发者ID:republique-et-canton-de-geneve,项目名称:chvote-protocol-poc,代码行数:22,代码来源:PolynomialAlgorithms.java

示例6: PKCS10

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Parses an encoded, signed PKCS #10 certificate request, verifying
 * the request's signature as it does so.  This constructor would
 * typically be used by a Certificate Authority, from which a new
 * certificate would then be constructed.
 *
 * @param data the DER-encoded PKCS #10 request.
 * @exception IOException for low level errors reading the data
 * @exception SignatureException when the signature is invalid
 * @exception NoSuchAlgorithmException when the signature
 *  algorithm is not supported in this environment
 */
public PKCS10(byte[] data)
throws IOException, SignatureException, NoSuchAlgorithmException {
    DerInputStream  in;
    DerValue[]      seq;
    AlgorithmId     id;
    byte[]          sigData;
    Signature       sig;

    encoded = data;

    //
    // Outer sequence:  request, signature algorithm, signature.
    // Parse, and prepare to verify later.
    //
    in = new DerInputStream(data);
    seq = in.getSequence(3);

    if (seq.length != 3)
        throw new IllegalArgumentException("not a PKCS #10 request");

    data = seq[0].toByteArray();            // reusing this variable
    id = AlgorithmId.parse(seq[1]);
    sigData = seq[2].getBitString();

    //
    // Inner sequence:  version, name, key, attributes
    //
    BigInteger      serial;
    DerValue        val;

    serial = seq[0].data.getBigInteger();
    if (!serial.equals(BigInteger.ZERO))
        throw new IllegalArgumentException("not PKCS #10 v1");

    subject = new X500Name(seq[0].data);
    subjectPublicKeyInfo = X509Key.parse(seq[0].data.getDerValue());

    // Cope with a somewhat common illegal PKCS #10 format
    if (seq[0].data.available() != 0)
        attributeSet = new PKCS10Attributes(seq[0].data);
    else
        attributeSet = new PKCS10Attributes();

    if (seq[0].data.available() != 0)
        throw new IllegalArgumentException("illegal PKCS #10 data");

    //
    // OK, we parsed it all ... validate the signature using the
    // key and signature algorithm we found.
    //
    try {
        sig = Signature.getInstance(id.getName());
        sig.initVerify(subjectPublicKeyInfo);
        sig.update(data);
        if (!sig.verify(sigData))
            throw new SignatureException("Invalid PKCS #10 signature");
    } catch (InvalidKeyException e) {
        throw new SignatureException("invalid key");
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:73,代码来源:PKCS10.java

示例7: modInv

import java.math.BigInteger; //导入方法依赖的package包/类
public static void modInv(int order) {
    int failCount = 0, successCount = 0, nonInvCount = 0;

    for (int i=0; i<SIZE; i++) {
        BigInteger x = fetchNumber(order);
        while(x.equals(BigInteger.ZERO))
            x = fetchNumber(order);
        BigInteger m = fetchNumber(order).abs();
        while(m.compareTo(BigInteger.ONE) != 1)
            m = fetchNumber(order).abs();

        try {
            BigInteger inv = x.modInverse(m);
            BigInteger prod = inv.multiply(x).remainder(m);

            if (prod.signum() == -1)
                prod = prod.add(m);

            if (prod.equals(BigInteger.ONE))
                successCount++;
            else
                failCount++;
        } catch(ArithmeticException e) {
            nonInvCount++;
        }
    }
    report("Modular Inverse for " + order + " bits", failCount);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:BigIntegerTest.java

示例8: encode

import java.math.BigInteger; //导入方法依赖的package包/类
public static String encode(BigInteger decoded) {
	StringBuilder sb = new StringBuilder();
	int rem = 0;
	while(true) {
		rem = (decoded.mod(BigInteger.valueOf(charMap.length))).intValue();
		sb.append(charMap[rem]);
		if(decoded.equals(BigInteger.ZERO)) break;
		decoded = decoded.divide(BigInteger.valueOf(charMap.length));
	}
	return sb.toString();
}
 
开发者ID:pawankumbhare4213,项目名称:TinyURL,代码行数:12,代码来源:Codec.java

示例9: generateKeyPair

import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public KeyPair generateKeyPair() {
    BigInteger p = safePrime(keySize / 2, random);
    BigInteger q = safePrime(keySize / 2, random);

    while (p.equals(q)) {
        q = safePrime(keySize / 2, random);
    }

    PublicKey publicKey = new BPPublicKey(p.multiply(q));
    PrivateKey privateKey = new BPPrivateKey();

    return new KeyPair(publicKey, privateKey);
}
 
开发者ID:woefe,项目名称:xmlrss,代码行数:15,代码来源:BPKeyPairGenerator.java

示例10: numBytes

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Calculate the number of bytes need
 * to encode the number
 *
 * @param val - number
 * @return number of min bytes used to encode the number
 */
public static int numBytes(String val) {

    BigInteger bInt = new BigInteger(val);
    int bytes = 0;

    while (!bInt.equals(BigInteger.ZERO)) {
        bInt = bInt.shiftRight(8);
        ++bytes;
    }
    if (bytes == 0) ++bytes;
    return bytes;
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:20,代码来源:ByteUtil.java

示例11: verifySignature

import java.math.BigInteger; //导入方法依赖的package包/类
/**
    * return true if the value r and s represent a DSA signature for
    * the passed in message (for standard DSA the message should be
    * a SHA-1 hash of the real message to be verified).
    */
@Override
public boolean verifySignature(
       byte[]      message,
       BigInteger  r,
       BigInteger  s)
{
	BigInteger e = new BigInteger(1, message);
	BigInteger n = key.getParameters().getN();

	// r in the range [1,n-1]
	if ( r.compareTo(ONE) < 0 || r.compareTo(n) >= 0 )
	{
		return false;
	}

	// s in the range [1,n-1]
	if ( s.compareTo(ONE) < 0 || s.compareTo(n) >= 0 )
	{
		return false;
	}

	BigInteger c = s.modInverse(n);

	BigInteger u1 = e.multiply(c).mod(n);
	BigInteger u2 = r.multiply(c).mod(n);

	ECPoint G = key.getParameters().getG();
	ECPoint Q = ((ECPublicKeyParameters)key).getQ();

	ECPoint point = G.multiply(u1).add(Q.multiply(u2));

	BigInteger v = point.getX().toBigInteger().mod(n);

	return v.equals(r);
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:41,代码来源:ECDSASigner.java

示例12: validateGx4

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Validates that g^x4 is not 1.
 *
 * @throws CryptoException if g^x4 is 1
 */
public static void validateGx4(BigInteger gx4)
    throws CryptoException
{
    if (gx4.equals(ONE))
    {
        throw new CryptoException("g^x validation failed.  g^x should not be 1.");
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:14,代码来源:JPAKEUtil.java

示例13: filterTransactions

import java.math.BigInteger; //导入方法依赖的package包/类
public List<org.ethereum.core.Transaction> filterTransactions(List<org.ethereum.core.Transaction> txsToRemove, List<org.ethereum.core.Transaction> txs, Map<RskAddress, BigInteger> accountNonces, Repository originalRepo, BigInteger minGasPrice) {
    List<org.ethereum.core.Transaction> txsResult = new ArrayList<>();
    for (org.ethereum.core.Transaction tx : txs) {
        try {
            logger.info("Pending transaction {} {}", toBI(tx.getNonce()), Hex.toHexString(tx.getHash()));
            RskAddress txSender = tx.getSender();

            logger.info("Examining transaction {} sender: {} value: {} nonce: {}", Hex.toHexString(tx.getHash()), txSender, Hex.toHexString(tx.getValue()), Hex.toHexString(tx.getNonce()));

            BigInteger txNonce = new BigInteger(1, tx.getNonce());

            BigInteger expectedNonce;

            if (accountNonces.containsKey(txSender)) {
                expectedNonce = new BigInteger(1, accountNonces.get(txSender).toByteArray()).add(BigInteger.ONE);
            } else {
                expectedNonce = originalRepo.getNonce(txSender.getBytes());
            }

            if (!(tx instanceof RemascTransaction) && tx.getGasPriceAsInteger().compareTo(minGasPrice) < 0) {
                logger.warn("Rejected transaction {} because of low gas account {}, removing tx from pending state.", Hex.toHexString(tx.getHash()), txSender);

                txsToRemove.add(tx);
                continue;
            }

            if (!expectedNonce.equals(txNonce)) {
                logger.warn("Invalid nonce, expected {}, found {}, tx {}", expectedNonce.toString(), txNonce.toString(), Hex.toHexString(tx.getHash()));
                continue;
            }

            accountNonces.put(txSender, txNonce);

            logger.info("Accepted transaction {} sender: {} value: {} nonce: {}", Hex.toHexString(tx.getHash()), txSender, Hex.toHexString(tx.getValue()), Hex.toHexString(tx.getNonce()));
        } catch (Exception e) {
            // Txs that can't be selected by any reason should be removed from pending state
            String hash = null == tx.getHash() ? "" : Hex.toHexString(tx.getHash());
            logger.warn("Error when processing transaction: " + hash, e);
            if (txsToRemove != null) {
                txsToRemove.add(tx);
            } else {
                logger.error("Can't remove invalid txs from pending state.");
            }
            continue;
        }

        txsResult.add(tx);
    }

    logger.info("Ending getTransactions {}", txsResult.size());

    return txsResult;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:54,代码来源:MinerUtils.java

示例14: crtCrypt

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * RSA private key operations with CRT. Algorithm and variable naming
 * are taken from PKCS#1 v2.1, section 5.1.2.
 */
private static byte[] crtCrypt(byte[] msg, RSAPrivateCrtKey key,
        boolean verify) throws BadPaddingException {
    BigInteger n = key.getModulus();
    BigInteger c0 = parseMsg(msg, n);
    BigInteger c = c0;
    BigInteger p = key.getPrimeP();
    BigInteger q = key.getPrimeQ();
    BigInteger dP = key.getPrimeExponentP();
    BigInteger dQ = key.getPrimeExponentQ();
    BigInteger qInv = key.getCrtCoefficient();
    BigInteger e = key.getPublicExponent();
    BigInteger d = key.getPrivateExponent();

    BlindingRandomPair brp;
    if (ENABLE_BLINDING) {
        brp = getBlindingRandomPair(e, d, n);
        c = c.multiply(brp.u).mod(n);
    }

    // m1 = c ^ dP mod p
    BigInteger m1 = c.modPow(dP, p);
    // m2 = c ^ dQ mod q
    BigInteger m2 = c.modPow(dQ, q);

    // h = (m1 - m2) * qInv mod p
    BigInteger mtmp = m1.subtract(m2);
    if (mtmp.signum() < 0) {
        mtmp = mtmp.add(p);
    }
    BigInteger h = mtmp.multiply(qInv).mod(p);

    // m = m2 + q * h
    BigInteger m = h.multiply(q).add(m2);

    if (ENABLE_BLINDING) {
        m = m.multiply(brp.v).mod(n);
    }
    if (verify && !c0.equals(m.modPow(e, n))) {
        throw new BadPaddingException("RSA private key operation failed");
    }

    return toByteArray(m, getByteLength(n));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:48,代码来源:RSACore.java

示例15: verifySignature

import java.math.BigInteger; //导入方法依赖的package包/类
public static boolean verifySignature(byte[] message, DSASignature ds, DSAPublicKey dpk) throws IOException {
    /* Inspired by Bouncycastle's DSASigner class */

    SHA1 md = new SHA1();
    md.update(message);
    byte[] sha_message = new byte[md.getDigestLength()];
    md.digest(sha_message);

    BigInteger m = new BigInteger(1, sha_message);

    BigInteger r = ds.getR();
    BigInteger s = ds.getS();

    BigInteger g = dpk.getG();
    BigInteger p = dpk.getP();
    BigInteger q = dpk.getQ();
    BigInteger y = dpk.getY();

    BigInteger zero = BigInteger.ZERO;

    if (log.isEnabled()) {
        log.log(60, "ssh-dss signature: m: " + m.toString(16));
        log.log(60, "ssh-dss signature: r: " + r.toString(16));
        log.log(60, "ssh-dss signature: s: " + s.toString(16));
        log.log(60, "ssh-dss signature: g: " + g.toString(16));
        log.log(60, "ssh-dss signature: p: " + p.toString(16));
        log.log(60, "ssh-dss signature: q: " + q.toString(16));
        log.log(60, "ssh-dss signature: y: " + y.toString(16));
    }

    if (zero.compareTo(r) >= 0 || q.compareTo(r) <= 0) {
        log.log(20, "ssh-dss signature: zero.compareTo(r) >= 0 || q.compareTo(r) <= 0");
        return false;
    }

    if (zero.compareTo(s) >= 0 || q.compareTo(s) <= 0) {
        log.log(20, "ssh-dss signature: zero.compareTo(s) >= 0 || q.compareTo(s) <= 0");
        return false;
    }

    BigInteger w = s.modInverse(q);

    BigInteger u1 = m.multiply(w).mod(q);
    BigInteger u2 = r.multiply(w).mod(q);

    u1 = g.modPow(u1, p);
    u2 = y.modPow(u2, p);

    BigInteger v = u1.multiply(u2).mod(p).mod(q);

    return v.equals(r);
}
 
开发者ID:fast-data-transfer,项目名称:fdt,代码行数:53,代码来源:DSASHA1Verify.java


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