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

Java Pack类代码示例

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

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



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

示例1: generateBytes

import org.spongycastle.util.Pack; //导入依赖的package包/类
/**
 * fill len bytes of the output buffer with bytes generated from the
 * derivation function.
 * 
 * @throws IllegalArgumentException
 *             if the size of the request will cause an overflow.
 * @throws DataLengthException
 *             if the out buffer is too small.
 */
public int generateBytes(byte[] out, int outOff, int len) throws DataLengthException,
        IllegalArgumentException
{
    if ((out.length - len) < outOff)
    {
        throw new DataLengthException("output buffer too small");
    }

    long oBytes = len;
    int outLen = digest.getDigestSize();

    //
    // this is at odds with the standard implementation, the
    // maximum value should be hBits * (2^32 - 1) where hBits
    // is the digest output size in bits. We can't have an
    // array with a long index at the moment...
    //
    if (oBytes > ((2L << 32) - 1))
    {
        throw new IllegalArgumentException("Output length too large");
    }

    int cThreshold = (int)((oBytes + outLen - 1) / outLen);

    byte[] dig = new byte[digest.getDigestSize()];

    byte[] C = new byte[4];
    Pack.intToBigEndian(counterStart, C, 0);

    int counterBase = counterStart & ~0xFF;

    for (int i = 0; i < cThreshold; i++)
    {
        digest.update(C, 0, C.length);
        digest.update(shared, 0, shared.length);

        if (iv != null)
        {
            digest.update(iv, 0, iv.length);
        }

        digest.doFinal(dig, 0);

        if (len > outLen)
        {
            System.arraycopy(dig, 0, out, outOff, outLen);
            outOff += outLen;
            len -= outLen;
        }
        else
        {
            System.arraycopy(dig, 0, out, outOff, len);
        }

        if (++C[3] == 0)
        {
            counterBase += 0x100;
            Pack.intToBigEndian(counterBase, C, 0);
        }
    }

    digest.reset();

    return (int)oBytes;
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:75,代码来源:ConcatKDFBytesGenerator.java


示例2: generateBytes

import org.spongycastle.util.Pack; //导入依赖的package包/类
/**
 * fill len bytes of the output buffer with bytes generated from the
 * derivation function.
 * 
 * @throws IllegalArgumentException
 *             if the size of the request will cause an overflow.
 * @throws DataLengthException
 *             if the out buffer is too small.
 */
public int generateBytes(byte[] out, int outOff, int len) throws DataLengthException,
        IllegalArgumentException
{
    if ((out.length - len) < outOff)
    {
        throw new DataLengthException("output buffer too small");
    }

    long oBytes = len;
    int outLen = digest.getDigestSize();

    //
    // this is at odds with the standard implementation, the
    // maximum value should be hBits * (2^32 - 1) where hBits
    // is the digest output size in bits. We can't have an
    // array with a long index at the moment...
    //
    if (oBytes > ((2L << 32) - 1))
    {
        throw new IllegalArgumentException("Output length too large");
    }

    int cThreshold = (int)((oBytes + outLen - 1) / outLen);

    byte[] dig = new byte[digest.getDigestSize()];

    byte[] c = new byte[4];
    Pack.intToBigEndian(counterStart, c, 0);

    int counterBase = counterStart & ~0xFF;

    for (int i = 0; i < cThreshold; i++)
    {
        digest.update(c, 0, c.length);
        digest.update(shared, 0, shared.length);

        if (iv != null)
        {
            digest.update(iv, 0, iv.length);
        }

        digest.doFinal(dig, 0);

        if (len > outLen)
        {
            System.arraycopy(dig, 0, out, outOff, outLen);
            outOff += outLen;
            len -= outLen;
        }
        else
        {
            System.arraycopy(dig, 0, out, outOff, len);
        }

        if (++c[3] == 0)
        {
            counterBase += 0x100;
            Pack.intToBigEndian(counterBase, c, 0);
        }
    }

    digest.reset();

    return (int)oBytes;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:75,代码来源:ConcatKDFBytesGenerator.java


示例3: updateRecordMACLength

import org.spongycastle.util.Pack; //导入依赖的package包/类
private static void updateRecordMACLength(Mac mac, int len) {
    byte[] longLen = Pack.longToLittleEndian(len & 0xFFFFFFFFL);
    mac.update(longLen, 0, longLen.length);
}
 
开发者ID:oversecio,项目名称:oversec_crypto,代码行数:5,代码来源:OversecChacha20Poly1305.java


示例4: encryptBlock

import org.spongycastle.util.Pack; //导入依赖的package包/类
private byte[] encryptBlock(byte[] in, int inOff, int inLen) throws InvalidCipherTextException {
    byte[] C = null, K = null, K1 = null, K2 = null;
    int len;

    if (cipher == null) {
        // Streaming mode.
        K1 = new byte[inLen];
        K2 = new byte[param.getMacKeySize() / 8];
        K = new byte[K1.length + K2.length];

        kdf.generateBytes(K, 0, K.length);

        if (V.length != 0) {
            System.arraycopy(K, 0, K2, 0, K2.length);
            System.arraycopy(K, K2.length, K1, 0, K1.length);
        } else {
            System.arraycopy(K, 0, K1, 0, K1.length);
            System.arraycopy(K, inLen, K2, 0, K2.length);
        }

        C = new byte[inLen];

        for (int i = 0; i != inLen; i++) {
            C[i] = (byte) (in[inOff + i] ^ K1[i]);
        }
        len = inLen;
    } else {
        // Block cipher mode.
        K1 = new byte[((IESWithCipherParameters) param).getCipherKeySize() / 8];
        K2 = new byte[param.getMacKeySize() / 8];
        K = new byte[K1.length + K2.length];

        kdf.generateBytes(K, 0, K.length);
        System.arraycopy(K, 0, K1, 0, K1.length);
        System.arraycopy(K, K1.length, K2, 0, K2.length);

        // If iv provided use it to initialise the cipher
        if (IV != null) {
            cipher.init(true, new ParametersWithIV(new KeyParameter(K1), IV));
        } else {
            cipher.init(true, new KeyParameter(K1));
        }

        C = new byte[cipher.getOutputSize(inLen)];
        len = cipher.processBytes(in, inOff, inLen, C, 0);
        len += cipher.doFinal(C, len);
    }

    // Convert the length of the encoding vector into a byte array.
    byte[] P2 = param.getEncodingV();
    byte[] L2 = new byte[4];
    if (V.length != 0 && P2 != null) {
        Pack.intToBigEndian(P2.length * 8, L2, 0);
    }

    // Apply the MAC.
    byte[] T = new byte[mac.getMacSize()];

    byte[] K2a = new byte[hash.getDigestSize()];
    hash.reset();
    hash.update(K2, 0, K2.length);
    hash.doFinal(K2a, 0);
    mac.init(new KeyParameter(K2a));
    mac.update(IV, 0, IV.length);
    mac.update(C, 0, C.length);
    if (P2 != null) {
        mac.update(P2, 0, P2.length);
    }
    if (V.length != 0) {
        mac.update(L2, 0, L2.length);
    }
    mac.doFinal(T, 0);

    // Output the triple (V,C,T).
    byte[] Output = new byte[V.length + len + T.length];
    System.arraycopy(V, 0, Output, 0, V.length);
    System.arraycopy(C, 0, Output, V.length, len);
    System.arraycopy(T, 0, Output, V.length + len, T.length);
    return Output;
}
 
开发者ID:mudpedal,项目名称:cgk-tetherj,代码行数:81,代码来源:EthereumIESEngine.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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