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


Java ByteUtils.concatenate方法代码示例

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

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

示例1: messageEncrypt

import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; //导入方法依赖的package包/类
public byte[] messageEncrypt(byte[] input)
    throws Exception
{

    int kDiv8 = k >> 3;

    // generate random r of length k div 8 bytes
    byte[] r = new byte[kDiv8];
    sr.nextBytes(r);

    // generate random vector r' of length k bits
    GF2Vector rPrime = new GF2Vector(k, sr);

    // convert r' to byte array
    byte[] rPrimeBytes = rPrime.getEncoded();

    // compute (input||r)
    byte[] mr = ByteUtils.concatenate(input, r);

    // compute H(input||r)
    messDigest.update(mr, 0, mr.length);
    byte[] hmr = new byte[messDigest.getDigestSize()];
    messDigest.doFinal(hmr, 0);


    // convert H(input||r) to error vector z
    GF2Vector z = Conversions.encode(n, t, hmr);

    // compute c1 = E(rPrime, z)
    byte[] c1 = McElieceCCA2Primitives.encryptionPrimitive((McElieceCCA2PublicKeyParameters)key, rPrime,
        z).getEncoded();

    // get PRNG object
    DigestRandomGenerator sr0 = new DigestRandomGenerator(new SHA1Digest());

    // seed PRNG with r'
    sr0.addSeedMaterial(rPrimeBytes);

    // generate random c2
    byte[] c2 = new byte[input.length + kDiv8];
    sr0.nextBytes(c2);

    // XOR with input
    for (int i = 0; i < input.length; i++)
    {
        c2[i] ^= input[i];
    }
    // XOR with r
    for (int i = 0; i < kDiv8; i++)
    {
        c2[input.length + i] ^= r[i];
    }

    // return (c1||c2)
    return ByteUtils.concatenate(c1, c2);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:57,代码来源:McEliecePointchevalCipher.java


示例2: messageEncrypt

import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; //导入方法依赖的package包/类
public byte[] messageEncrypt(byte[] input)
    throws Exception
{

    // generate random vector r of length k bits
    GF2Vector r = new GF2Vector(k, sr);

    // convert r to byte array
    byte[] rBytes = r.getEncoded();

    // compute (r||input)
    byte[] rm = ByteUtils.concatenate(rBytes, input);

    // compute H(r||input)
    messDigest.update(rm, 0, rm.length);
    byte[] hrm = new byte[messDigest.getDigestSize()];
    messDigest.doFinal(hrm, 0);

    // convert H(r||input) to error vector z
    GF2Vector z = Conversions.encode(n, t, hrm);

    // compute c1 = E(r, z)
    byte[] c1 = McElieceCCA2Primitives.encryptionPrimitive((McElieceCCA2PublicKeyParameters)key, r, z)
        .getEncoded();

    // get PRNG object
    DigestRandomGenerator sr0 = new DigestRandomGenerator(new SHA1Digest());

    // seed PRNG with r'
    sr0.addSeedMaterial(rBytes);

    // generate random c2
    byte[] c2 = new byte[input.length];
    sr0.nextBytes(c2);

    // XOR with input
    for (int i = 0; i < input.length; i++)
    {
        c2[i] ^= input[i];
    }

    // return (c1||c2)
    return ByteUtils.concatenate(c1, c2);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:45,代码来源:McElieceFujisakiCipher.java


示例3: messageDecrypt

import org.bouncycastle.pqc.math.linearalgebra.ByteUtils; //导入方法依赖的package包/类
public byte[] messageDecrypt(byte[] input)
    throws Exception
{

    int c1Len = (n + 7) >> 3;
    int c2Len = input.length - c1Len;

    // split ciphertext (c1||c2)
    byte[][] c1c2 = ByteUtils.split(input, c1Len);
    byte[] c1 = c1c2[0];
    byte[] c2 = c1c2[1];

    // decrypt c1 ...
    GF2Vector hrmVec = GF2Vector.OS2VP(n, c1);
    GF2Vector[] decC1 = McElieceCCA2Primitives.decryptionPrimitive((McElieceCCA2PrivateKeyParameters)key,
        hrmVec);
    byte[] rBytes = decC1[0].getEncoded();
    // ... and obtain error vector z
    GF2Vector z = decC1[1];

    // get PRNG object
    DigestRandomGenerator sr0 = new DigestRandomGenerator(new SHA1Digest());

    // seed PRNG with r'
    sr0.addSeedMaterial(rBytes);

    // generate random sequence
    byte[] mBytes = new byte[c2Len];
    sr0.nextBytes(mBytes);

    // XOR with c2 to obtain m
    for (int i = 0; i < c2Len; i++)
    {
        mBytes[i] ^= c2[i];
    }

    // compute H(r||m)
    byte[] rmBytes = ByteUtils.concatenate(rBytes, mBytes);
    byte[] hrm = new byte[messDigest.getDigestSize()];
    messDigest.update(rmBytes, 0, rmBytes.length);
    messDigest.doFinal(hrm, 0);


    // compute Conv(H(r||m))
    hrmVec = Conversions.encode(n, t, hrm);

    // check that Conv(H(m||r)) = z
    if (!hrmVec.equals(z))
    {

        throw new Exception("Bad Padding: invalid ciphertext");

    }

    // return plaintext m
    return mBytes;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:58,代码来源:McElieceFujisakiCipher.java



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