我如何从java创建函数到objective-c

问题描述:

我是一个新鲜的IOS开发人员,面临加密和解密的问题。我如何从java创建函数到objective-c

解密代码(JAVA)

 byte[] keyPass = pass.getBytes("ASCII"); 
     byte[] aesIV = new byte[16]; 
     byte[] Decryptdata = Base64.decode(encodedString, Base64.NO_WRAP); 
     System.arraycopy(Decryptdata, 0, aesIV, 0, 16); 
     byte[] data = new byte[Decryptdata.length - 16]; 
     System.arraycopy(Decryptdata, 16, data, 0, dataToDecrypt.length - 16); 
     Key aesKey = new SecretKeySpec(keyPass, "AES"); 
     IvParameterSpec ivSpec = new IvParameterSpec(aesIV); 
     Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding"); 
     cipher.init(Cipher.DECRYPT_MODE, aesKey, ivSpec); 
     Text = new String(cipher.doFinal(data), "UTF-8"); 

加密代码(JAVA)

 byte[] keyPass = pass.getBytes("ASCII"); 
     final Key key = new SecretKeySpec(keyPass, "AES"); 
     final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding"); 
     byte[] byteMessage = text.getBytes("UTF-8"); 
     cipher.init(Cipher.ENCRYPT_MODE, key); 
     byte[] cipherText = cipher.doFinal(byteMessage); 
     byte[] ivByte = cipher.getIV(); 

     byte[] bytesTotal = new byte[ivByte.length+cipherText.length]; 
     System.arraycopy(ivByte, 0, bytesTotal, 0, ivByte.length); 
     System.arraycopy(cipherText, 0, bytesTotal, ivByte.length, cipherText.length); 
     encyoted = Base64.encodeToString(bytesTotal, Base64.NO_WRAP); 

如何创建加密和在Objective-C解密?

+0

1.以十六进制形式提供加密数据,解密数据和IV。 2.使用全长密钥,AES支持128,192和256位密钥。我们会等你做你的工作,提供一个[mcve]。 – zaph

在iOS设备上使用Common Crypto “如何创建从Java到Objective-C的功能”

研究,编写代码和调试。必要时重复。