Search in sources :

Example 1 with Mac

use of org.spongycastle.crypto.Mac in project jmulticard by ctt-gob-es.

the class AmAESCrypto method getMAC.

@Override
public byte[] getMAC(final byte[] data) {
    byte[] n = new byte[this.sscBytes.length + data.length];
    System.arraycopy(this.sscBytes, 0, n, 0, this.sscBytes.length);
    System.arraycopy(data, 0, n, this.sscBytes.length, data.length);
    n = addPadding(n);
    final BlockCipher cipher = new AESEngine();
    final Mac mac = new CMac(cipher, 64);
    mac.init(this.keyP);
    mac.update(n, 0, n.length);
    final byte[] out = new byte[mac.getMacSize()];
    mac.doFinal(out, 0);
    return out;
}
Also used : AESEngine(org.spongycastle.crypto.engines.AESEngine) CMac(org.spongycastle.crypto.macs.CMac) CBCBlockCipher(org.spongycastle.crypto.modes.CBCBlockCipher) BlockCipher(org.spongycastle.crypto.BlockCipher) PaddedBufferedBlockCipher(org.spongycastle.crypto.paddings.PaddedBufferedBlockCipher) Mac(org.spongycastle.crypto.Mac) CMac(org.spongycastle.crypto.macs.CMac)

Aggregations

BlockCipher (org.spongycastle.crypto.BlockCipher)1 Mac (org.spongycastle.crypto.Mac)1 AESEngine (org.spongycastle.crypto.engines.AESEngine)1 CMac (org.spongycastle.crypto.macs.CMac)1 CBCBlockCipher (org.spongycastle.crypto.modes.CBCBlockCipher)1 PaddedBufferedBlockCipher (org.spongycastle.crypto.paddings.PaddedBufferedBlockCipher)1