Android JAVA代码中Camellia 128bit的提供程序名称语法是什么??我尝试从Cipher.getInstance("AES/CBC/PKCS7Padding")更改为Cipher.getInstance("Camellia/CBC/PKCS7Padding","BC"),但它显示提供者BC不提供“Camellia/CBC/PKCS7Padding.”。下面是我的代码
try {
String keyString = "Potatoman55@";//length of key is 16
Cipher desCipher = Cipher.getInstance("Camellia/CBC/PKCS7Padding","BC");
byte[] key = new byte[0];
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
key = keyString.getBytes(StandardCharsets.UTF_8);
}
}
MessageDigest sha = MessageDigest.getInstance("SHA-1");
key = sha.digest(key);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
key = Arrays.copyOf(key, 16); // use only first 128 bit
}
SecretKeySpec secretKeySpec = new SecretKeySpec(key, "AES");
desCipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
String plainText = "hello wolrd";
System.out.println("plaintext: "+plainText);
byte[] text = plainText.getBytes("UTF-8");
byte[] textencrypted = desCipher.doFinal(text);
String textEnc = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
System.out.println("encrypted: " + Base64.getEncoder().encodeToString(textencrypted));
textEnc = Base64.getEncoder().encodeToString(textencrypted);
}
result.success(textEnc);
} catch (Exception ex) {
System.out.println(ex.toString());
}发布于 2020-11-03 10:35:35
我以这个代码new org.bouncycastle.jce.provider.BouncyCastleProvider());作为提供者成功地运行了代码。非常感谢this的评论。下面是完整的语法
Cipher desCipher = Cipher.getInstance("Camellia/CBC/PKCS7Padding",new org.bouncycastle.jce.provider.BouncyCastleProvider());https://stackoverflow.com/questions/64655886
复制相似问题