[英]How can i decrypt the xml file in iOS with AES/CBC/PKCS5Padding standard,in android the file has been decrypted ,all keys like salt, IV
private static Cipher getCipher(int mode) throws Exception {
Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding");
//a random Init. Vector. just for testing
byte[] iv = "e675f725e675f725".getBytes("UTF-8");
c.init(mode, generateKey(), new IvParameterSpec(iv));
return c;
}
private static String Decrypt(String encrypted) throws Exception {
byte[] decodedValue = new Base64().decode(encrypted.getBytes("UTF-8")); // new BASE64Decoder().decodeBuffer(encrypted);
Cipher c = getCipher(Cipher.DECRYPT_MODE);
byte[] decValue = c.doFinal(decodedValue);
return new String(decValue);
}
private static Key generateKey() throws Exception {
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
char[] password = "3x5FBNs!".toCharArray();
byte[] salt = "S@1tS@1t".getBytes("UTF-8");
KeySpec spec = new PBEKeySpec(password, salt, 65536, 128);
SecretKey tmp = factory.generateSecret(spec);
byte[] encoded = tmp.getEncoded();
return new SecretKeySpec(encoded, "AES");
}
我嘗試使用 RNCryptor 但無法解密。 任何人都可以幫助我應該使用哪個庫,因為我已經獲得了加密文件但不知道它是如何加密的。
為了使用 RNCryptor,最好在兩個平台上都使用它。
從上一個問題來看,加密數據似乎是字節,而不是 Base64 編碼的。
Apple Common Crypto 提供的原語是 Security.framework 的一部分。 要使用的標頭是#import <CommonCrypto/CommonCrypto.h>
並且您將在CommonCryptor.h
和CommonKeyDerivation.h
找到您需要的接口。
嘗試 iOS 並添加代碼以及 Android 和 iOS 代碼的所有輸入和輸出參數和數據的十六進制轉儲。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.