作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
是否可以使用JCE来执行CCM?
我在 Internet 上看到很多使用非 JCE bouncycaSTLe 类的示例。特别是,我看到他们调用 init 并传入 CCMParameters 对象。
问题是,这个 CCMParameters 对象不是从 AlgorthmParameters 或 AlgorithmParameterSpec 派生的,所以似乎没有办法将它传递到 Cipher.init()(在使用 Cipher.getInstance("AES/CCM/NoPadding")).
如何做到这一点?
最佳答案
您好,这是 AES-CCM 算法的示例代码其中所有常用名称都是输入参数。注意十六进制数据字节和所有其他事情
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 = "abcdefghijklm".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());
}
}
关于java - 如何将 AES CCM 与 BouncycaSTLe JCE 提供程序一起使用 - CCMParameters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38062249/
我是一名优秀的程序员,十分优秀!