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

Java CMac类代码示例

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

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



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

示例1: scp03_kdf

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
private static byte[] scp03_kdf(byte[] key, byte constant, byte[] context, int blocklen_bits) {
    // 11 bytes
    byte[] label = new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

    ByteArrayOutputStream bo = new ByteArrayOutputStream();
    try {
        bo.write(label); // 11 bytes of label
        bo.write(constant); // constant for the last byte
        bo.write(0x00); // separator
        bo.write((blocklen_bits >> 8) & 0xFF); // block size in two bytes
        bo.write(blocklen_bits & 0xFF);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
    byte[] blocka = bo.toByteArray();
    byte[] blockb = context;

    BlockCipher cipher = new AESEngine();
    CMac cmac = new CMac(cipher);
    KDFCounterBytesGenerator kdf = new KDFCounterBytesGenerator(cmac);
    kdf.init(new KDFCounterParameters(key, blocka, blockb, 8)); // counter size in bits

    byte[] cgram = new byte[blocklen_bits / 8];
    kdf.generateBytes(cgram, 0, cgram.length);
    return cgram;
}
 
开发者ID:martinpaljak,项目名称:GlobalPlatformPro,代码行数:27,代码来源:GPCrypto.java


示例2: s2v

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
byte[] s2v(byte[] macKey, byte[] plaintext, byte[]... associatedData) {
	// Maximum permitted AD length is the block size in bits - 2
	if (associatedData.length > 126) {
		// SIV mode cannot be used safely with this many AD fields
		throw new IllegalArgumentException("too many Associated Data fields");
	}

	final CipherParameters params = new KeyParameter(macKey);
	final CMac mac = new CMac(threadLocalCipher.get());
	mac.init(params);

	byte[] d = mac(mac, BYTES_ZERO);

	for (byte[] s : associatedData) {
		d = xor(dbl(d), mac(mac, s));
	}

	final byte[] t;
	if (plaintext.length >= 16) {
		t = xorend(plaintext, d);
	} else {
		t = xor(dbl(d), pad(plaintext));
	}

	return mac(mac, t);
}
 
开发者ID:cryptomator,项目名称:siv-mode,代码行数:27,代码来源:SivMode.java


示例3: getMAC

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
@Override
public byte[] getMAC(byte[] data) {

	byte[] n = new byte[sscBytes.length + data.length];
	System.arraycopy(sscBytes, 0, n, 0, sscBytes.length);
	System.arraycopy(data, 0, n, sscBytes.length, data.length);
	n = addPadding(n);

	BlockCipher cipher = new AESFastEngine();
	Mac mac = new CMac(cipher, 64);

	mac.init(keyP);
	mac.update(n, 0, n.length);
	byte[] out = new byte[mac.getMacSize()];

	mac.doFinal(out, 0);

	return out;
}
 
开发者ID:tsenger,项目名称:animamea,代码行数:20,代码来源:AmAESCrypto.java


示例4: performCBC8

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
/**
 * AES [FIPS 197] SHALL be used in CMAC-mode [SP 800-38B] with a MAC length of 8 bytes.
 *
 * @param data the data to MAC
 * @param key the key to use
 * @return the 8 byte MAC of the data
 */
public static byte[] performCBC8(byte[] data, byte[] key) {

    // mac size in bits (64 bits = 8 bytes)
    final Mac cbc8 = new CMac(new AESEngine(), 64);
    CipherParameters params = new KeyParameter(key);
    cbc8.init(params);

    byte[] result = new byte[8];
    cbc8.update(data, 0, data.length);
    cbc8.doFinal(result, 0);

    return result;
}
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:21,代码来源:AESUtils.java


示例5: EAXBlockCipher

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
/**
 * Constructor that accepts an instance of a block cipher engine.
 *
 * @param cipher the engine to use
 */
public EAXBlockCipher(BlockCipher cipher)
{
    blockSize = cipher.getBlockSize();
    mac = new CMac(cipher);
    macBlock = new byte[blockSize];
    bufBlock = new byte[blockSize * 2];
    associatedTextMac = new byte[mac.getMacSize()];
    nonceMac = new byte[mac.getMacSize()];
    this.cipher = new SICBlockCipher(cipher);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:16,代码来源:EAXBlockCipher.java


示例6: EAXBlockCipher

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
/**
 * Constructor that accepts an instance of a block cipher engine.
 *
 * @param cipher the engine to use
 */
public EAXBlockCipher(BlockCipher cipher)
{
    blockSize = cipher.getBlockSize();
    mac = new CMac(cipher);
    macBlock = new byte[blockSize];
    associatedTextMac = new byte[mac.getMacSize()];
    nonceMac = new byte[mac.getMacSize()];
    this.cipher = new SICBlockCipher(cipher);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:15,代码来源:EAXBlockCipher.java


示例7: testExceptions

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
private void testExceptions()
{
    try 
    {
        CMac mac = new CMac(new AESEngine());
        mac.init(new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16]));
        fail("CMac does not accept IV");
    } catch(IllegalArgumentException e)
    {
        // Expected
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:13,代码来源:CMacTest.java


示例8: scp03_mac

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
public static byte[] scp03_mac(byte[] keybytes, byte[] msg, int lengthBits) {
    // Use BouncyCastle light interface.
    BlockCipher cipher = new AESEngine();
    CMac cmac = new CMac(cipher);
    cmac.init(new KeyParameter(keybytes));
    cmac.update(msg, 0, msg.length);
    byte[] out = new byte[cmac.getMacSize()];
    cmac.doFinal(out, 0);
    return Arrays.copyOf(out, lengthBits / 8);
}
 
开发者ID:martinpaljak,项目名称:GlobalPlatformPro,代码行数:11,代码来源:GPCrypto.java


示例9: main

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
public static void main(String[] args)
{
    testMac(new HMac(new SHA1Digest()), new KeyParameter(generateNonce(20)), 3);
    testMac(new SkeinMac(SkeinMac.SKEIN_512, 128), new KeyParameter(generateNonce(64)), 2);
    testMac(new SipHash(), new KeyParameter(generateNonce(16)), 1);
    testMac(new CMac(new AESFastEngine()), new KeyParameter(generateNonce(16)), 3);
    testMac(new GMac(new GCMBlockCipher(new AESFastEngine())), new ParametersWithIV(new KeyParameter(
            generateNonce(16)), generateNonce(16)), 5);
    testMac(new Poly1305(new NullEngine(16)), new ParametersWithIV(generatePoly1305Key(), generateNonce(16)), 1);
    testMac(new Poly1305(new AESFastEngine()), new ParametersWithIV(generatePoly1305Key(), generateNonce(16)), 1);
    testMac(new Poly1305Reference(new NullEngine(16)), new ParametersWithIV(generatePoly1305Key(),
            generateNonce(16)), 1);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:14,代码来源:MacThroughputTest.java


示例10: CMAC

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
public CMAC()
{
    super(new CMac(new DESEngine()));
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:5,代码来源:DES.java


示例11: CMAC

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
public CMAC()
{
    super(new CMac(new DESedeEngine()));
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:5,代码来源:DESede.java


示例12: AESCMAC

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
public AESCMAC()
{
    super(new CMac(new AESFastEngine()));
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:5,代码来源:AES.java


示例13: testCMac

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
private void testCMac(BlockCipher cipher, byte[] keyBytes, byte[] input, byte[] expected)
{
    Mac mac = new CMac(cipher, cipher.getBlockSize() * 8);

    KeyParameter key = new KeyParameter(keyBytes);

    mac.init(key);

    mac.update(input, 0, input.length);

    byte[] out = new byte[mac.getMacSize()];

    mac.doFinal(out, 0);

    if (!areEqual(out, expected))
    {
        fail("Failed - expected " + Strings.fromByteArray(Hex.encode(expected)) + " got " + new String(Hex.encode(out)));
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:20,代码来源:CMacTest.java


示例14: CMAC

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
public CMAC()
{
    super(new CMac(new SEEDEngine()));
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:5,代码来源:SEED.java


示例15: CMAC

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
public CMAC()
{
    super(new CMac(new Shacal2Engine()));
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:5,代码来源:Shacal2.java


示例16: CMAC

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
public CMAC()
{
    super(new CMac(new SM4Engine()));
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:5,代码来源:SM4.java


示例17: CMAC_256

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
public CMAC_256()
{
    super(new CMac(new ThreefishEngine(256)));
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:5,代码来源:Threefish.java


示例18: CMAC_512

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
public CMAC_512()
{
    super(new CMac(new ThreefishEngine(512)));
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:5,代码来源:Threefish.java


示例19: CMAC_1024

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
public CMAC_1024()
{
    super(new CMac(new ThreefishEngine(1024)));
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:5,代码来源:Threefish.java


示例20: CMAC

import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
public CMAC()
{
    super(new CMac(new BlowfishEngine()));
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:5,代码来源:Blowfish.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java Torch类代码示例发布时间:2022-05-22
下一篇:
Java StepExecution类代码示例发布时间: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