• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java McElieceKeyGenerationParameters类的典型用法和代码示例

java 1次浏览

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

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

示例1: initialize

点赞 2

import org.bouncycastle.pqc.crypto.mceliece.McElieceKeyGenerationParameters; //导入依赖的package包/类
public void initialize(AlgorithmParameterSpec params)
    throws InvalidAlgorithmParameterException
{
    kpg = new McElieceKeyPairGenerator();
    super.initialize(params);
    ECCKeyGenParameterSpec ecc = (ECCKeyGenParameterSpec)params;

    McElieceKeyGenerationParameters mccKGParams = new McElieceKeyGenerationParameters(new SecureRandom(), new McElieceParameters(ecc.getM(), ecc.getT()));
    kpg.init(mccKGParams);
}
 

开发者ID:Appdome,
项目名称:ipack,
代码行数:11,
代码来源:McElieceKeyPairGeneratorSpi.java

示例2: performTest

点赞 2

import org.bouncycastle.pqc.crypto.mceliece.McElieceKeyGenerationParameters; //导入依赖的package包/类
public void performTest()
{
    int numPassesKPG = 1;
    int numPassesEncDec = 10;
    Random rand = new Random();
    byte[] mBytes;
    for (int j = 0; j < numPassesKPG; j++)
    {

        McElieceParameters params = new McElieceParameters();
        McElieceKeyPairGenerator mcElieceKeyGen = new McElieceKeyPairGenerator();
        McElieceKeyGenerationParameters genParam = new McElieceKeyGenerationParameters(keyRandom, params);

        mcElieceKeyGen.init(genParam);
        AsymmetricCipherKeyPair pair = mcElieceKeyGen.generateKeyPair();

        ParametersWithRandom param = new ParametersWithRandom(pair.getPublic(), keyRandom);
        Digest msgDigest = new SHA256Digest();
        McEliecePKCSDigestCipher mcEliecePKCSDigestCipher = new McEliecePKCSDigestCipher(new McEliecePKCSCipher(), msgDigest);


        for (int k = 1; k <= numPassesEncDec; k++)
        {
            System.out.println("############### test: " + k);
            // initialize for encryption
            mcEliecePKCSDigestCipher.init(true, param);

            // generate random message
            int mLength = (rand.nextInt() & 0x1f) + 1;
            mBytes = new byte[mLength];
            rand.nextBytes(mBytes);

            // encrypt
            mcEliecePKCSDigestCipher.update(mBytes, 0, mBytes.length);
            byte[] enc = mcEliecePKCSDigestCipher.messageEncrypt();

            // initialize for decryption
            mcEliecePKCSDigestCipher.init(false, pair.getPrivate());
            byte[] constructedmessage = mcEliecePKCSDigestCipher.messageDecrypt(enc);

            // XXX write in McElieceFujisakiDigestCipher?
            msgDigest.update(mBytes, 0, mBytes.length);
            byte[] hash = new byte[msgDigest.getDigestSize()];
            msgDigest.doFinal(hash, 0);

            boolean verified = true;
            for (int i = 0; i < hash.length; i++)
            {
                verified = verified && hash[i] == constructedmessage[i];
            }

            if (!verified)
            {
                fail("en/decryption fails");
            }
            else
            {
                System.out.println("test okay");
                System.out.println();
            }

        }
    }

}
 

开发者ID:credentials,
项目名称:irma_future_id,
代码行数:66,
代码来源:McEliecePKCSCipherTest.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)