قالب وردپرس درنا توس
Home / IOS Development / IOS – AES128 encryption in fast

IOS – AES128 encryption in fast



I have a problem with AES-128 encryption. The encrypted string in iOS is different to Android.

Below is android code:

  public static String encryptMaster (String message, String mykey) {

String Encrypted = "";
String messageVal = message;
String mykeyVal = mykey;

SecretKey key = new SecretKeySpec (mykeyVal.getBytes (), "AES");
// Utilities.showLogE ("key", "" + key.toString ());
try {
Cipher ecipher = Cipher.getInstance ("AES");
ecipher.init (Cipher.ENCRYPT_MODE, key);
byte [] utf8 = messageVal.getBytes ("UTF-8");
byte [] enc = ecipher.doFinal (utf8);
// encrypted = Utilities.encodeBase64String (enc);
encrypted = new BASE64Encoder (). code (enc);
// Utilities.showLogE ("encrypted", "" + encrypted);
} catch (except e) {
// Log.d (Constants.LOGKEY, "Exception");
e.printStackTrace ();
}

return encrypted;
}

Below is iOS code:

. . .

was encryptionKey = EncryptionAndConversion.sharedInstance.encryptionKey () // returns any key. Get the same as Android

whose encryption key.length> = 1
6 { la index1 = encryptionKey.startIndex.advancedBy (16) // .endIndex.advancedBy (-4) encryptionKey = encryptionKey.substringToIndex (index1) } print (encryptionkey) la stringFromJson = jsonToString1 (params) was data1 = EncryptionAndConversion.sharedInstance.convertStringToAES128 (stringFromJson, key: encryptionKey) // The result of data1 is different to Android. . . . func convertStringToAES128 (message: String, key myKey: String) -> String { //// ---- Plain Text -> AES128 la cipherData = message.dataUsingEncoding (NSUTF8StringEncoding) ?. AES128EncryptedDataWithKey (myKey) // base 64 encryption leave base64Text = cipherData? .base64EncodedStringWithOptions (NSDataBase64EncodingOptions.init (rawValue: 0)) print (base64Text) return base64Text! as strict } func jsonToString1 (json: AnyObject) -> String { was convertedString: String = "" do { let data1 = try NSJSONSerialization.dataWithJSONObject (json, alternatives: NSJSONWritingOptions.init (rawValue: 0)) // first convert json to the data convertedString = String (data: data1, encoding: NSUTF8StringEncoding)! // The data is converted to the string print ("convertedString: (convertedString)" // // - here is your string } grab myJSONError { convertedString = "" print (myJSONError) } return conversion string }

Where am I going wrong?


Source link