aes128 cmac java_java.security.NoSuchAlgorithmException:没有这样的算法:提供者BC的CmacAES...

import javax.crypto.Mac;

import javax.crypto.SecretKey;

import javax.crypto.spec.SecretKeySpec;

/**

* Class to calculate CMAC which is used as PRF in KDF for SCP03 PseudoRandom CardChallenge generation

*/

public class Cmac {

/**

* Tested CMAC against official TestVectors ({@link 'http://csrc.nist.gov/publications/nistpubs/800-38B/SP_800-38B.pdf'})

* CMAC used as PRF in KDF

*/

public static byte[] calc(byte[] keyBytes, byte[] data) throws ApduGeneratorException {

try {

SecretKey key = new SecretKeySpec(keyBytes, 0, keyBytes.length, "AES");

Mac mac = Mac.getInstance("CmacAES", BouncyCastleProvider.PROVIDER_NAME);

mac.init(key);

byte[] hash = mac.doFinal(data);

return hash;

} catch (Exception e) {

throw new ApduGeneratorException(e.getMessage());

}

}

}此代码导致此类异常:

java.security.NoSuchAlgorithmException: no such algorithm: CmacAES for provider BC

at sun.security.jca.GetInstance.getService(Unknown Source)

at javax.crypto.JceSecurity.getInstance(JceSecurity.java:97)

at javax.crypto.Mac.getInstance(Mac.java:222)

at com.quantag.globalplatform.sm.Cmac.calc(Cmac.java:23)

at app.executors.LoadAppletExecutor$1.call(LoadAppletExecutor.java:102)

at app.executors.LoadAppletExecutor$1.call(LoadAppletExecutor.java:1)

at javafx.concurrent.Task$TaskCallable.call(Unknown Source)

at java.util.concurrent.FutureTask.run(Unknown Source)

at javafx.concurrent.Service.lambda$null$492(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at javafx.concurrent.Service.lambda$executeTask$493(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)我已经安装了JCE unlimited 8并添加了:security.provider.N=org.bouncycastle.jce.provider.BouncyCastleProvider

根据Provider Installation docs。

但我仍然得到这个例外。我错过了什么?

我正在使用BC的这种版本:bcprov-jdk15on-154.jar。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值