• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java BigIntegers类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getSM2Z

import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
public static byte[] getSM2Z(byte[] userID, ASN1ObjectIdentifier curveOid,
        BigInteger pubPointX, BigInteger pubPointY) {
    SM3Digest digest = new SM3Digest();

    addUserID(digest, userID);

    X9ECParameters ecParams = GMNamedCurves.getByOID(curveOid);
    addFieldElement(digest, ecParams.getCurve().getA());
    addFieldElement(digest, ecParams.getCurve().getB());
    addFieldElement(digest, ecParams.getG().getAffineXCoord());
    addFieldElement(digest, ecParams.getG().getAffineYCoord());

    int fieldSize = (ecParams.getCurve().getFieldSize() + 7) / 8;
    byte[] bytes = BigIntegers.asUnsignedByteArray(fieldSize, pubPointX);
    digest.update(bytes, 0, fieldSize);

    bytes = BigIntegers.asUnsignedByteArray(fieldSize, pubPointY);
    digest.update(bytes, 0, fieldSize);

    byte[] result = new byte[digest.getDigestSize()];
    digest.doFinal(result, 0);
    return result;
}
 
开发者ID:xipki,项目名称:xitk,代码行数:24,代码来源:GMUtil.java


示例2: calculateZeroKnowledgeProof

import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
/**
 * Calculate a zero knowledge proof of x using Schnorr's signature.
 * The returned array has two elements {g^v, r = v-x*h} for x.
 */
public static BigInteger[] calculateZeroKnowledgeProof(
    BigInteger p,
    BigInteger q,
    BigInteger g,
    BigInteger gx,
    BigInteger x,
    String participantId,
    Digest digest,
    SecureRandom random)
{
    BigInteger[] zeroKnowledgeProof = new BigInteger[2];

    /* Generate a random v, and compute g^v */
    BigInteger vMin = ZERO;
    BigInteger vMax = q.subtract(ONE);
    BigInteger v = BigIntegers.createRandomInRange(vMin, vMax, random);

    BigInteger gv = g.modPow(v, p);
    BigInteger h = calculateHashForZeroKnowledgeProof(g, gv, gx, participantId, digest); // h

    zeroKnowledgeProof[0] = gv;
    zeroKnowledgeProof[1] = v.subtract(x.multiply(h)).mod(q); // r = v-x*h

    return zeroKnowledgeProof;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:30,代码来源:JPAKEUtil.java


示例3: calculatePrivate

import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
BigInteger calculatePrivate(DHParameters dhParams, SecureRandom random)
{
    BigInteger p = dhParams.getP();
    int limit = dhParams.getL();

    if (limit != 0)
    {
        return new BigInteger(limit, random).setBit(limit - 1);
    }

    BigInteger min = TWO;
    int m = dhParams.getM();
    if (m != 0)
    {
        min = ONE.shiftLeft(m - 1);
    }

    BigInteger max = p.subtract(TWO);
    BigInteger q = dhParams.getQ();
    if (q != null)
    {
        max = q.subtract(TWO);
    }

    return BigIntegers.createRandomInRange(min, max, random);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:27,代码来源:DHKeyGeneratorHelper.java


示例4: ECPrivateKeyStructure

import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
public ECPrivateKeyStructure(
    BigInteger    key,
    DERBitString  publicKey,
    ASN1Encodable parameters)
{
    byte[] bytes = BigIntegers.asUnsignedByteArray(key);

    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(new ASN1Integer(1));
    v.add(new DEROctetString(bytes));

    if (parameters != null)
    {
        v.add(new DERTaggedObject(true, 0, parameters));
    }

    if (publicKey != null)
    {
        v.add(new DERTaggedObject(true, 1, publicKey));
    }

    seq = new DERSequence(v);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:25,代码来源:ECPrivateKeyStructure.java


示例5: isFinalSolutionCorrect

import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
@Override
public boolean isFinalSolutionCorrect(BigInteger guessedSecret) {
    // BigInteger correct = new
    // BigInteger("25091756309879652045519159642875354611257005804552159157");
    // if (correct.compareTo(guessedSecret) == 0) {
    // return true;
    // } else {
    // return false;
    // }

    computer.setSecret(guessedSecret);
    try {
        Point p = computer.mul(checkPoint);
        byte[] pms = BigIntegers.asUnsignedByteArray(curve.getKeyBits() / 8, p.getX());
        return Arrays.equals(checkPMS, pms);
    } catch (DivisionException ex) {
        LOGGER.debug(ex);
        return false;
    }
}
 
开发者ID:RUB-NDS,项目名称:TLS-Attacker,代码行数:21,代码来源:RealDirectMessageECOracle.java


示例6: generatePremasterSecret

import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
public byte[] generatePremasterSecret() throws IOException
{
    try
    {
        BigInteger S = srpServer != null
            ?   srpServer.calculateSecret(srpPeerCredentials)
            :   srpClient.calculateSecret(srpPeerCredentials);

        // TODO Check if this needs to be a fixed size
        return BigIntegers.asUnsignedByteArray(S);
    }
    catch (CryptoException e)
    {
        throw new TlsFatalAlert(AlertDescription.illegal_parameter, e);
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:17,代码来源:TlsSRPKeyExchange.java


示例7: encrypt

import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
/**
 * Generate and encapsulate a random session key.
 *
 * @param out    the output buffer for the encapsulated key.
 * @param outOff the offset for the output buffer.
 * @param keyLen the length of the random session key.
 * @return the random session key.
 */
public CipherParameters encrypt(byte[] out, int outOff, int keyLen)
    throws IllegalArgumentException
{
    if (key.isPrivate())
    {
        throw new IllegalArgumentException("Public key required for encryption");
    }

    BigInteger n = key.getModulus();
    BigInteger e = key.getExponent();

    // Generate the ephemeral random and encode it    
    BigInteger r = BigIntegers.createRandomInRange(ZERO, n.subtract(ONE), rnd);

    // Encrypt the random and encode it     
    BigInteger c = r.modPow(e, n);
    byte[] C = BigIntegers.asUnsignedByteArray((n.bitLength() + 7) / 8, c);
    System.arraycopy(C, 0, out, outOff, C.length);

    return generateKey(n, r, keyLen);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:30,代码来源:RSAKeyEncapsulation.java


示例8: generatePrivateKey

import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
private static BigInteger generatePrivateKey(BigInteger q, SecureRandom random)
    {
        // B.1.2 Key Pair Generation by Testing Candidates
        int minWeight = q.bitLength() >>> 2;
        for (;;)
        {
            // TODO Prefer this method? (change test cases that used fixed random)
            // B.1.1 Key Pair Generation Using Extra Random Bits
//            BigInteger x = new BigInteger(q.bitLength() + 64, random).mod(q.subtract(ONE)).add(ONE);

            BigInteger x = BigIntegers.createRandomInRange(ONE, q.subtract(ONE), random);
            if (WNafUtil.getNafWeight(x) >= minWeight)
            {
                return x;
            }
        }
    }
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:18,代码来源:DSAKeyPairGenerator.java


示例9: selectGenerator

import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
static BigInteger selectGenerator(BigInteger p, SecureRandom random)
     {
         BigInteger pMinusTwo = p.subtract(TWO);
         BigInteger g;

/*
          * RFC 2631 2.2.1.2 (and see: Handbook of Applied Cryptography 4.81)
 */
         do
         {
             BigInteger h = BigIntegers.createRandomInRange(TWO, pMinusTwo, random);

             g = h.modPow(TWO, p);
         }
         while (g.equals(ONE));

         return g;
     }
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:19,代码来源:CramerShoupParametersGenerator.java


示例10: ECPrivateKey

import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
public ECPrivateKey(
    int orderBitLength,
    BigInteger key,
    DERBitString publicKey,
    ASN1Encodable parameters)
{
    byte[] bytes = BigIntegers.asUnsignedByteArray((orderBitLength + 7) / 8, key);

    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(new ASN1Integer(1));
    v.add(new DEROctetString(bytes));

    if (parameters != null)
    {
        v.add(new DERTaggedObject(true, 0, parameters));
    }

    if (publicKey != null)
    {
        v.add(new DERTaggedObject(true, 1, publicKey));
    }

    seq = new DERSequence(v);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:26,代码来源:ECPrivateKey.java


示例11: performTest

import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
public void performTest()
    throws Exception
{
    BigInteger pSubOne = DHStandardGroups.rfc3526_2048.getP().subtract(ONE);
    for (int i = 0; i < 10; ++i)
    {
        BigInteger message = BigIntegers.createRandomInRange(ONE, pSubOne, RND);

        BigInteger m1 = encDecTest(message);
        BigInteger m2 = labelledEncDecTest(message, "myRandomLabel");
        BigInteger m3 = encDecEncodingTest(message);
        BigInteger m4 = labelledEncDecEncodingTest(message, "myOtherCoolLabel");

        if (!message.equals(m1) || !message.equals(m2) || !message.equals(m3) || !message.equals(m4))
        {
            fail("decrypted message != original message");
        }
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:20,代码来源:CramerShoupTest.java


示例12: findBetaValues

import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
private static ECFieldElement[] findBetaValues(ECCurve c)
{
    BigInteger q = c.getField().getCharacteristic();
    BigInteger e = q.divide(ECConstants.THREE);

    // Search for a random value that generates a non-trival cube root of 1
    SecureRandom random = new SecureRandom();
    BigInteger b;
    do
    {
        BigInteger r = BigIntegers.createRandomInRange(ECConstants.TWO, q.subtract(ECConstants.TWO), random);
        b = r.modPow(e, q);
    }
    while (b.equals(ECConstants.ONE));

    ECFieldElement beta = c.fromBigInteger(b);

    return new ECFieldElement[]{ beta, beta.square() }; 
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:20,代码来源:DiscoverEndomorphisms.java


示例13: generateSignature

import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
/**
 * generate a signature for the loaded message using the key we were
 * initialised with.
 */
public byte[] generateSignature()
    throws CryptoException
{
    createSignatureBlock();

    BigInteger t = new BigInteger(1, cipher.processBlock(block, 0, block.length));
    BigInteger nSubT = kParam.getModulus().subtract(t);

    clearBlock(block);

    BigInteger v = kParam.getModulus().shiftRight(2);

    if (t.compareTo(nSubT) > 0)
    {
        return BigIntegers.asUnsignedByteArray((kParam.getModulus().bitLength() + 7) / 8, nSubT);
    }
    else
    {
        return BigIntegers.asUnsignedByteArray((kParam.getModulus().bitLength() + 7) / 8, t);
    }
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:26,代码来源:X931Signer.java


示例14: decodeFPPoint

import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
@Deprecated
public static ECPoint decodeFPPoint(ECCurve curve, byte[] data) {
    // Patched org.bouncycastle.math.ec.ECCurve#decodePoint code.
    int expectedLength = (curve.getFieldSize() + 7) / 8;
    if (expectedLength != data.length) {
        throw new IllegalArgumentException("incorrect data length for compact encoding");
    }

    BigInteger X = BigIntegers.fromUnsignedByteArray(data, 0, expectedLength);
    ECPoint p = decompressFPPoint(curve, X);

    if (!satisfiesCofactor(curve, p)) {
        throw new IllegalArgumentException("invalid point");
    }

    return p;
}
 
开发者ID:horrorho,项目名称:InflatableDonkey,代码行数:18,代码来源:ECPointsCompact.java


示例15: importKey

import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
@Override
public Optional<ECPublicKey> importKey(String curveName, byte[] data) {
    int fieldLength = ECAssistant.fieldLength(curveName);
    if (fieldLength(data.length) != fieldLength) {
        logger.warn("-- importKey() - bad data length: {} curve: {} data:0x{}",
                data.length, curveName, Hex.toHexString(data));
    }

    if (!checkType(data[0])) {
        logger.warn("-- importKey() - bad data type: 0x{}", Integer.toHexString(data[0]));
    }

    BigInteger x = BigIntegers.fromUnsignedByteArray(data, 1, fieldLength);
    BigInteger y = BigIntegers.fromUnsignedByteArray(data, 1 + fieldLength, fieldLength);

    return ECKeyFactories.publicKeyFactory()
            .createECPublicKey(x, y, curveName);
}
 
开发者ID:horrorho,项目名称:InflatableDonkey,代码行数:19,代码来源:ECPublicKeyImportX963.java


示例16: importKey

import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
@Override
public Optional<ECPrivateKey> importKey(String curveName, byte[] data) {
    X9ECParameters x9ECParameters = ECAssistant.x9ECParameters(curveName);
    int fieldLength = ECAssistant.fieldLength(x9ECParameters);
    if (fieldLength(data.length) != fieldLength) {
        logger.warn("-- importKey() - bad data length: {} curve: {} data:0x{}",
                data.length, curveName, Hex.toHexString(data));
    }


    BigInteger x = BigIntegers.fromUnsignedByteArray(data, 0, fieldLength);
    BigInteger y = ECPointsCompact.y(x9ECParameters.getCurve(), x);
    BigInteger d = BigIntegers.fromUnsignedByteArray(data, fieldLength, fieldLength);

    return ECKeyFactories.privateKeyFactory()
            .createECPrivateKey(x, y, d, curveName);
}
 
开发者ID:horrorho,项目名称:InflatableDonkey,代码行数:18,代码来源:ECPrivateKeyImportCompact.java


示例17: ECPrivateKey

import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
public ECPrivateKey(
    BigInteger key,
    DERBitString publicKey,
    ASN1Encodable parameters)
{
    byte[] bytes = BigIntegers.asUnsignedByteArray(key);

    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(new ASN1Integer(1));
    v.add(new DEROctetString(bytes));

    if (parameters != null)
    {
        v.add(new DERTaggedObject(true, 0, parameters));
    }

    if (publicKey != null)
    {
        v.add(new DERTaggedObject(true, 1, publicKey));
    }

    seq = new DERSequence(v);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:25,代码来源:ECPrivateKey.java


示例18: generateClientKeyExchange

import org.bouncycastle.util.BigIntegers; //导入依赖的package包/类
public byte[] generateClientKeyExchange() throws IOException
    {
        // TODO RFC 2246 7.4.72
        /*
         * If the client certificate already contains a suitable Diffie-Hellman key, then
         * Yc is implicit and does not need to be sent again. In this case, the Client Key
         * Exchange message will be sent, but will be empty.
         */
//        return new byte[0];

        /*
         * Generate a keypair (using parameters from server key) and send the public value
         * to the server.
         */
        DHBasicKeyPairGenerator dhGen = new DHBasicKeyPairGenerator();
        dhGen.init(new DHKeyGenerationParameters(handler.getRandom(),
            dhAgreeServerPublicKey.getParameters()));
        this.dhAgreeClientKeyPair = dhGen.generateKeyPair();
        BigInteger Yc = ((DHPublicKeyParameters)dhAgreeClientKeyPair.getPublic()).getY();
        return BigIntegers.asUnsignedByteArray(Yc);
    }
 
开发者ID:coova,项目名称:jradius,代码行数:22,代码来源:TlsDHKeyExchange.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FtpClient类代码示例发布时间:2022-05-21
下一篇:
Java EntityAIMoveIndoors类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap