Closed rushikesh1980 closed 3 months ago
Hi @rushikesh1980 ,
You can get the desired behavior by using AESCMAC
as the algorithm in this sample: https://github.com/aws-samples/aws-cloudhsm-jce-examples/blob/sdk5/src/main/java/com/amazonaws/cloudhsm/examples/HMACOperationsRunner.java#L68.
A quick example cmac function that builds on the HMACOperationsRunner example:
public static void cmac() throws Exception {
String plainText = "This is a sample Plain Text Message!";
Key key = SymmetricKeys.generateAESKey(256, "HmacTest");
String algorithm = "AESCMAC";
byte[] cloudHsmDigest = digest(plainText.getBytes("UTF-8"), key, algorithm, CloudHsmProvider.PROVIDER_NAME);
System.out.println("CloudHSM CMAC= " + Base64.getEncoder().encodeToString(cloudHsmDigest));
}
Give that a try and see if you can integrate it into your code. Thanks!
Hopefully this worked out, please re-open if needed!
I would like to generate CMAC using AWS HSM java SDK
I would like to calculate CMAC value according to attached file out of method available which method i should use to calculate CMAC earlier i had used digest method but when I compared the result with online CMAC generator it was not matching with CMAC generated programmatically Need your assistance here
Please have a look at my below code and tell me which method I should use
package com.trimble.crypto.cmac;
import com.amazonaws.cloudhsm.jce.provider.CloudHsmProvider; import com.trimble.crypto.util.IntializeCloudHSM; import org.bouncycastle.crypto.BlockCipher; import org.bouncycastle.crypto.engines.AESEngine; import org.bouncycastle.crypto.macs.CMac; import org.bouncycastle.crypto.params.KeyParameter;
import javax.crypto.; import javax.crypto.spec.SecretKeySpec; import java.nio.ByteBuffer; import java.security.; import java.util.Base64;
public class CMACCalculator {
}