Ad
How To Encrypt & Decrypt Using Camellia 128bit In Android JAVA Code?
What is the provider name syntax for Camellia 128bit in Android JAVA code?? i try to change from Cipher.getInstance("AES/CBC/PKCS7Padding")
into Cipher.getInstance("Camellia/CBC/PKCS7Padding","BC")
but it says Provider BC does not provide "Camellia/CBC/PKCS7Padding". Below is my code
try {
String keyString = "[email protected]";//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());
}
Ad
Answer
I successfully run the code by this code new org.bouncycastle.jce.provider.BouncyCastleProvider());
as the provider. Big thanks to this comment. below is the full syntax
Cipher desCipher = Cipher.getInstance("Camellia/CBC/PKCS7Padding",new org.bouncycastle.jce.provider.BouncyCastleProvider());
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad