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

Java DSAValidationParameters类代码示例

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

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



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

示例1: generateParameters_FIPS186_2

import org.bouncycastle.crypto.params.DSAValidationParameters; //导入依赖的package包/类
private DSAParameters generateParameters_FIPS186_2()
{
    byte[]          seed = new byte[20];
    byte[]          part1 = new byte[20];
    byte[]          part2 = new byte[20];
    byte[]          u = new byte[20];
    int             n = (L - 1) / 160;
    byte[]          w = new byte[L / 8];

    if (!(digest instanceof SHA1Digest))
    {
        throw new IllegalStateException("can only use SHA-1 for generating FIPS 186-2 parameters");
    }

    for (;;)
    {
        random.nextBytes(seed);

        hash(digest, seed, part1);
        System.arraycopy(seed, 0, part2, 0, seed.length);
        inc(part2);
        hash(digest, part2, part2);

        for (int i = 0; i != u.length; i++)
        {
            u[i] = (byte)(part1[i] ^ part2[i]);
        }

        u[0] |= (byte)0x80;
        u[19] |= (byte)0x01;

        BigInteger q = new BigInteger(1, u);

        if (!q.isProbablePrime(certainty))
        {
            continue;
        }

        byte[] offset = Arrays.clone(seed);
        inc(offset);

        for (int counter = 0; counter < 4096; ++counter)
        {
            for (int k = 0; k < n; k++)
            {
                inc(offset);
                hash(digest, offset, part1);
                System.arraycopy(part1, 0, w, w.length - (k + 1) * part1.length, part1.length);
            }

            inc(offset);
            hash(digest, offset, part1);
            System.arraycopy(part1, part1.length - ((w.length - (n) * part1.length)), w, 0, w.length - n * part1.length);

            w[0] |= (byte)0x80;

            BigInteger x = new BigInteger(1, w);

            BigInteger c = x.mod(q.shiftLeft(1));

            BigInteger p = x.subtract(c.subtract(ONE));

            if (p.bitLength() != L)
            {
                continue;
            }

            if (p.isProbablePrime(certainty))
            {
                BigInteger g = calculateGenerator_FIPS186_2(p, q, random);

                return new DSAParameters(p, q, g, new DSAValidationParameters(seed, counter));
            }
        }
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:77,代码来源:DSAParametersGenerator.java


示例2: generateParameters_FIPS186_2

import org.bouncycastle.crypto.params.DSAValidationParameters; //导入依赖的package包/类
private DSAParameters generateParameters_FIPS186_2()
{
    byte[]          seed = new byte[20];
    byte[]          part1 = new byte[20];
    byte[]          part2 = new byte[20];
    byte[]          u = new byte[20];
    int             n = (L - 1) / 160;
    byte[]          w = new byte[L / 8];

    if (!(digest instanceof SHA1Digest))
    {
        throw new IllegalStateException("can only use SHA-1 for generating FIPS 186-2 parameters");
    }

    for (;;)
    {
        random.nextBytes(seed);

        hash(digest, seed, part1, 0);
        System.arraycopy(seed, 0, part2, 0, seed.length);
        inc(part2);
        hash(digest, part2, part2, 0);

        for (int i = 0; i != u.length; i++)
        {
            u[i] = (byte)(part1[i] ^ part2[i]);
        }

        u[0] |= (byte)0x80;
        u[19] |= (byte)0x01;

        BigInteger q = new BigInteger(1, u);

        if (!isProbablePrime(q))
        {
            continue;
        }

        byte[] offset = Arrays.clone(seed);
        inc(offset);

        for (int counter = 0; counter < 4096; ++counter)
        {
            {
                for (int k = 1; k <= n; k++)
                {
                    inc(offset);
                    hash(digest, offset, w, w.length - k * part1.length);
                }

                int remaining = w.length - (n * part1.length);
                inc(offset);
                hash(digest, offset, part1, 0);
                System.arraycopy(part1, part1.length - remaining, w, 0, remaining);

                w[0] |= (byte)0x80;
            }

            BigInteger x = new BigInteger(1, w);

            BigInteger c = x.mod(q.shiftLeft(1));

            BigInteger p = x.subtract(c.subtract(ONE));

            if (p.bitLength() != L)
            {
                continue;
            }

            if (isProbablePrime(p))
            {
                BigInteger g = calculateGenerator_FIPS186_2(p, q, random);

                return new DSAParameters(p, q, g, new DSAValidationParameters(seed, counter));
            }
        }
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:79,代码来源:DSAParametersGenerator.java


示例3: performTest

import org.bouncycastle.crypto.params.DSAValidationParameters; //导入依赖的package包/类
public void performTest()
{
    BigInteger              r = new BigInteger("68076202252361894315274692543577577550894681403");
    BigInteger              s = new BigInteger("1089214853334067536215539335472893651470583479365");
    DSAParametersGenerator  pGen = new DSAParametersGenerator();

    pGen.init(512, 80, random);

    DSAParameters           params = pGen.generateParameters();
    DSAValidationParameters pValid = params.getValidationParameters();

    if (pValid.getCounter() != 105)
    {
        fail("Counter wrong");
    }

    if (!pValue.equals(params.getP()) || !qValue.equals(params.getQ()))
    {
        fail("p or q wrong");
    }

    DSAKeyPairGenerator         dsaKeyGen = new DSAKeyPairGenerator();
    DSAKeyGenerationParameters  genParam = new DSAKeyGenerationParameters(keyRandom, params);

    dsaKeyGen.init(genParam);

    AsymmetricCipherKeyPair  pair = dsaKeyGen.generateKeyPair();

    ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), keyRandom);

    DSASigner dsa = new DSASigner();

    dsa.init(true, param);

    byte[] message = BigIntegers.asUnsignedByteArray(new BigInteger("968236873715988614170569073515315707566766479517"));
    BigInteger[] sig = dsa.generateSignature(message);

    if (!r.equals(sig[0]))
    {
        fail("r component wrong.", r, sig[0]);
    }

    if (!s.equals(sig[1]))
    {
        fail("s component wrong.", s, sig[1]);
    }

    dsa.init(false, pair.getPublic());

    if (!dsa.verifySignature(message, sig[0], sig[1]))
    {
        fail("verification fails");
    }

    dsa2Test1();
    dsa2Test2();
    dsa2Test3();
    dsa2Test4();
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:60,代码来源:DSATest.java


示例4: performTest

import org.bouncycastle.crypto.params.DSAValidationParameters; //导入依赖的package包/类
public void performTest()
{
    BigInteger              r = new BigInteger("68076202252361894315274692543577577550894681403");
    BigInteger              s = new BigInteger("1089214853334067536215539335472893651470583479365");
    DSAParametersGenerator  pGen = new DSAParametersGenerator();

    pGen.init(512, 20, random);

    DSAParameters           params = pGen.generateParameters();
    DSAValidationParameters pValid = params.getValidationParameters();

    if (pValid.getCounter() != 105)
    {
        fail("Counter wrong");
    }

    if (!pValue.equals(params.getP()) || !qValue.equals(params.getQ()))
    {
        fail("p or q wrong");
    }

    DSAKeyPairGenerator         dsaKeyGen = new DSAKeyPairGenerator();
    DSAKeyGenerationParameters  genParam = new DSAKeyGenerationParameters(keyRandom, params);

    dsaKeyGen.init(genParam);

    AsymmetricCipherKeyPair  pair = dsaKeyGen.generateKeyPair();

    ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), keyRandom);

    DSASigner dsa = new DSASigner();

    dsa.init(true, param);

    byte[] message = BigIntegers.asUnsignedByteArray(new BigInteger("968236873715988614170569073515315707566766479517"));
    BigInteger[] sig = dsa.generateSignature(message);

    if (!r.equals(sig[0]))
    {
        fail("r component wrong.", r, sig[0]);
    }

    if (!s.equals(sig[1]))
    {
        fail("s component wrong.", s, sig[1]);
    }

    dsa.init(false, pair.getPublic());

    if (!dsa.verifySignature(message, sig[0], sig[1]))
    {
        fail("verification fails");
    }

    //dsa2Test1();
    //dsa2Test2();
    //dsa2Test3();
    //dsa2Test4();
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:60,代码来源:DSATest.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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