繁体   English   中英

如何使用 AES/CBC/PKCS5Padding 标准在 iOS 中解密 xml 文件,在 android 中文件已被解密,所有密钥如 salt、IV

[英]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.hCommonKeyDerivation.h找到您需要的接口。

尝试 iOS 并添加代码以及 Android 和 iOS 代码的所有输入和输出参数和数据的十六进制转储。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM