Search in sources :

Example 1 with SM4Engine

use of com.github.zhenwei.core.crypto.engines.SM4Engine in project LinLong-Java by zhenwei1108.

the class Mac method cmac.

public byte[] cmac(KeyEnum alg, byte[] key, byte[] source) throws WeGooCryptoException {
    BlockCipher engine;
    switch(alg) {
        case AES_128:
        case AES_256:
            engine = new AESEngine();
            break;
        default:
            engine = new SM4Engine();
    }
    CMac cMac = new CMac(engine);
    cMac.init(new KeyParameter(key));
    cMac.update(source, 0, source.length);
    byte[] result = new byte[cMac.getMacSize()];
    cMac.doFinal(result, 0);
    return result;
}
Also used : AESEngine(com.github.zhenwei.core.crypto.engines.AESEngine) CMac(com.github.zhenwei.core.crypto.macs.CMac) BlockCipher(com.github.zhenwei.core.crypto.BlockCipher) SM4Engine(com.github.zhenwei.core.crypto.engines.SM4Engine) KeyParameter(com.github.zhenwei.core.crypto.params.KeyParameter)

Aggregations

BlockCipher (com.github.zhenwei.core.crypto.BlockCipher)1 AESEngine (com.github.zhenwei.core.crypto.engines.AESEngine)1 SM4Engine (com.github.zhenwei.core.crypto.engines.SM4Engine)1 CMac (com.github.zhenwei.core.crypto.macs.CMac)1 KeyParameter (com.github.zhenwei.core.crypto.params.KeyParameter)1