我如何使用AES / CBC / PKCS5Padding标准解密iOS中的xml文件,在android文件已被解密后,所有的键都像盐,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

查看:225
本文介绍了我如何使用AES / CBC / PKCS5Padding标准解密iOS中的xml文件,在android文件已被解密后,所有的键都像盐,IV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

私有静态Cipher getCipher(int mode)throws异常{
Cipher c = Cipher.getInstance(AES / CBC / PKCS5Padding);

//一个随机的Init。向量。只是为了测试
byte [] iv =e675f725e675f725.getBytes(UTF-8);

c.init(mode,generateKey(),new IvParameterSpec(iv));
return c;
}


private static String Decrypt(String encrypted)throws异常{

byte [] decodedValue = new Base64()。的getBytes( UTF-8)); // new BASE64Decoder()。decodeBuffer(encrypted);

密码c = getCipher(Cipher.DECRYPT_MODE);
byte [] decValue = c.doFinal(decodedValue);

return new String(decValue);
}

private static Key generateKey()throws异常{
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();
返回新的SecretKeySpec(编码,AES);
}

我尝试使用RNCryptor,但无法解密。任何人都可以帮助我使用哪个库,因为我有加密的文件,不知道它是如何被加密的。

解决方案

为了使用RNCryptor,最好在两个平台上使用它。



从上一个问题,加密数据似乎是字节,而不是Base64编码。



Apple Common Crypto提供的原始图形是安全性.framework。要使用的标题是 #import< CommonCrypto / CommonCrypto.h> ,您将在 CommonCryptor.h CommonKeyDerivation.h



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


      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");
  }

I tried to use RNCryptor but could not decrypt. Can anybody help me which library should i use because i have got the encrypted file and don't know how it has been encrypted.

解决方案

In order to use RNCryptor it is best to use it on both platforms.

From a previous question it seems that the encrypted data was bytes, not Base64 encoded.

The primitives supplied by Apple Common Crypto and are part of the Security.framework. The header to use is #import <CommonCrypto/CommonCrypto.h> and you will find the interfaces you need in CommonCryptor.h and CommonKeyDerivation.h.

Make an attempt for iOS and add the code along with hex dumps of all input and output parameters and data both for the Android and iOS code.

这篇关于我如何使用AES / CBC / PKCS5Padding标准解密iOS中的xml文件,在android文件已被解密后,所有的键都像盐,IV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆