Recent projects using AES encryption, but in the Internet to find a lot of libraries are OC and Java encryption can not decrypt items, because our server is written in Java, so can not be used for iOS is a big trouble, Android is more leisurely to write in Java, so nothing. However, in the degree Niang body searched all over, or let me find this library, source remember not clear, before looking for a lot of many libraries. The following records the use of the method.
Example: Http://pan.baidu.com/s/1dDktRPn
OC Invocation Method:
viewcontroller.m// aestest//// Created by du Jia Li on 14-9-22.// Copyright (c) 2014 du Jia Li. All rights reserved.//#import "ViewController.h" #include "nsdata+aes256.h" @interface Viewcontroller () @ End@implementation viewcontroller-(void) viewdidload{ [Super viewdidload];//do no additional setup after loading The view, typically from a nib. nsstring* message = @ "Magic AES"; nsstring* str = [NSData aes256encryptwithplaintext:message]; nsstring* res = [NSData aes256decryptwithciphertext:str]; NSLog (@ "%@", str); NSLog (@ "%@", res);} -(void) didreceivememorywarning{ [Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end
Java Call Method:
Package Com.test.aesforandroid;import Android.os.bundle;import Android.app.activity;import android.util.Log;import Android.view.menu;public class Mainactivity extends Activity {@Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); AES MAes = new AES (); String mstring = "magical AES"; byte[] mBytes = null;try {mBytes = mstring.getbytes ("UTF8");} catch (Exception e) {//Todo:hand Le exception}string enstring = Maes.encrypt (mBytes); LOG.I ("aes123", enstring); String destring = Maes.decrypt (enstring); LOG.I ("aes123", destring);} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is PR Esent.getmenuinflater (). Inflate (R.menu.main, menu); return true;}}
Original address: http://blog.csdn.net/qqmcy/article/details/39483075
OC and Java-generic AES encryption decryption