Hallo hier ist Beispielcode für AES-CCM algo , wo alle üblichen Namen Eingabe-Parameter sind. kümmern sich um HEX Datenbytes und alle anderen Dinge
import org.bouncycastle.crypto.BlockCipher;
import org.bouncycastle.crypto.InvalidCipherTextException;
import org.bouncycastle.crypto.engines.AESEngine;
import org.bouncycastle.crypto.modes.CCMBlockCipher;
import org.bouncycastle.crypto.params.CCMParameters;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.util.encoders.Hex;
public class AesCcm {
public static void main(String[] args) throws IllegalStateException, InvalidCipherTextException {
int macSize = 125;
byte[] key = new byte[32];
byte[] keybyte = "test123".getBytes();
byte[] inputNouc = "abcd".getBytes();
for (int I = 0; I < keybyte.length; I++) {
key[I] = keybyte[I];
}
// Input data in HEX format
String input = "ed88fe7b95fa0ffa190b7ab33933fa";
byte[] inputData= Hex.decode(input);
BlockCipher engine = new AESEngine();
CCMParameters params = new CCMParameters(new KeyParameter(key),
macSize, inputNouc, null);
CCMBlockCipher cipher = new CCMBlockCipher(engine);
cipher.init(true, params);
byte[] outputText = new byte[cipher.getOutputSize(inputData.length)];
int outputLen = cipher.processBytes(inputData, 0, inputData.length,
outputText , 0);
cipher.doFinal(outputText, outputLen);
// outputText and mac are in bytes
System.out.println(outputText);
System.out.println(cipher.getMac());
}
}
Also das ist schön, aber die Frage war über JCE verwenden, nicht die bouncycastle proprietäre API. – nsayer
Ich habe an BC gearbeitet Also habe ich keine Ahnung von JCE –