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:そのようなアルゴリズム:プロバイダのCmacAES BC
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)
IはすでにJCE unlimited 8をインストールして追加しました:security.provider.N=org.bouncycastle.jce.provider.BouncyCastleProvider
Provider Installation docsに記載の方法。
しかし、私はまだこの例外を取得しています。私は何を逃したのですか?
私はこのようなバージョンのBC:bcprov-jdk15on-154.jarを使用しています。この新しいコードで
Mac mac = Mac.getInstance("CmacAES", BouncyCastleProvider.PROVIDER_NAME);
:
bouncycastleバージョン –
を言及してください。そうであれば、それを直接インスタンス化することもできます。 http://stackoverflow.com/questions/28516804/how-to-use-bouncycastles-cmac – pvg
このテストを実行する場合は、アサルトのために失敗しましたが、例外はありません。 –