本文整理汇总了Java中org.bouncycastle.crypto.macs.CMac类的典型用法代码示例。如果您正苦于以下问题:Java CMac类的具体用法?Java CMac怎么用?Java CMac使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CMac类属于org.bouncycastle.crypto.macs包,在下文中一共展示了CMac类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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
}
}
示例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);
}
示例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);
}
示例10: CMAC
import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
public CMAC()
{
super(new CMac(new DESEngine()));
}
示例11: CMAC
import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
public CMAC()
{
super(new CMac(new DESedeEngine()));
}
示例12: AESCMAC
import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
public AESCMAC()
{
super(new CMac(new AESFastEngine()));
}
示例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)));
}
}
示例14: CMAC
import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
public CMAC()
{
super(new CMac(new SEEDEngine()));
}
示例15: CMAC
import org.bouncycastle.crypto.macs.CMac; //导入依赖的package包/类
public CMAC()
{
super(new CMac(new Shacal2Engine()));
}